unash / barragerenderer Goto Github PK
View Code? Open in Web Editor NEW一个 iOS 上的弹幕渲染库.
Home Page: https://github.com/unash/BarrageRenderer
License: MIT License
一个 iOS 上的弹幕渲染库.
Home Page: https://github.com/unash/BarrageRenderer
License: MIT License
初始化弹幕后,第一条弹幕是正常从边缘滑动出来的(假设从右到左的弹幕),而是距离右边屏幕一段距离闪现。后面的字幕都是正常的。请问这是Bug吗?
mandatorySize 如何使用
请问我想设置弹幕的背景框的size怎么设置呢
我的数据源是200条数据,当执行到200条之后就报了这个错误,是执行完还要什么操作吗?
libc++abi.dylib: terminate_handler unexpectedly threw an exception
(void)setAllViews{
[self initBarrageRenderer];
NSSafeObject * safeObj = [[NSSafeObject alloc]initWithObject:self withSelector:@selector(autoSendBarrage)];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:safeObj selector:@selector(excute) userInfo:nil repeats:YES];
}
(void)initBarrageRenderer
{
_renderer = [[BarrageRenderer alloc]init];
_renderer.view.backgroundColor = UIColorFromRGB(SubjectColorValue);
_renderer.canvasMargin = UIEdgeInsetsMake(0, 0, 70, 0);
[self addSubview:_renderer.view];
[self sendSubviewToBack:_renderer.view];
}
(void)setDataStartWith:(NSMutableArray *)loadArray{
_modelArr = [NSMutableArray array];
for (NSDictionary *tempDict in loadArray) {
BarrageModel *model = [[BarrageModel alloc]initWithDict:tempDict];
[_modelArr addObject:model];
}
[_renderer start];
}
(void)autoSendBarrage{
NSInteger spriteNumber = [_renderer spritesNumberWithName:nil];
if (spriteNumber <= 20) {
[_renderer receive:[self walkTextSpriteDescriptorWithDirection:BarrageWalkDirectionR2L]];
}
}
(BarrageDescriptor *)walkTextSpriteDescriptorWithDirection:(NSInteger)direction
{
BarrageModel *model = _modelArr[_index];
BarrageDescriptor * descriptor = [[BarrageDescriptor alloc]init];
descriptor.spriteName = NSStringFromClass([BarrageWalkTextSprite class]);
descriptor.params[@"text"] = [NSString stringWithFormat:@"%@ %@",model.UserNick,model.content];
descriptor.params[@"textColor"] = [UIColor blueColor];
descriptor.params[@"speed"] = @(100 * (double)random()/RAND_MAX+50);
descriptor.params[@"direction"] = @(direction);
descriptor.params[@"trackNumber"] = @20; // 轨道数量
_index ++;
return descriptor;
}
设置弹幕的显示位置canvasMargin, 一开始竖屏时没有这样的效果,横屏后才有效.......Demo中的代码
_renderer.canvasMargin = UIEdgeInsetsMake(100, 10, 10, 10);
引入UIView对象池, 这个 代码 体现在哪啊
download project but can't run.这个下载下来就跑不了啊。需要什么特别设置?
首先感谢作者的付出。
现在默认都是上往下,我希望第一个出现的轨道,是最底部的轨道。
我试着继承 BarrageWalkTextSprite , 然后覆盖- (CGPoint)originInBounds:(CGRect)rect withSprites:(NSArray *)sprites 返回你设置的弹幕初始位置.
- (CGPoint)originInBounds:(CGRect)rect withSprites:(NSArray *)sprites
{
CGPoint point = [super originInBounds:rect withSprites:sprites];
return point+200;
}
初始位置改变了,但是路线,变成了从”右下->左上“的斜线。
希望可以添加一个接口,设置初始显示的轨道。谢谢
是否支持弹幕中加载网络图片,我的需求是需要头像和文字,头像是从网络获取的
添加一个缓存池存储弹幕,现在bindingView每次都要新建一个view
barrageImageScaleToSize里面试试用CoreImage替代CoreGraphics来处理图片
NSLog(@"视频总长速度:%d",time);
NSMutableArray *descriptors = [NSMutableArray new];
for (int i = 0; i< time; i++) {
[descriptors addObject:[self walkTextSpriteDescriptorWithDirection:BarrageWalkDirectionR2L withIndex:i withAdd:NO]];
}
[_renderer load:descriptors];
[_renderer start];
index 为上述for循环里的 i ,delay是绑定事件参数,可是视频播放 弹幕却是一个脑儿得横着飘出来,视频播到一半 弹幕已经显示完全了
descriptor.params[@"delay"] = @(index);
比如在视频某个时间点有很多弹幕,这个时候所有弹幕都重叠在了一起,这个目前有解决方案么?
在设置弹幕的text时,如果text中不包含中文(测试过字母和数字混合),那么设置其颜色不起作用,显示为蓝色,且带下划线.只有当弹幕含有中文时,设置其颜色才起作用.text为NSTaggedPointerString类型,请问这种情况应该怎么解决?
_renderer.canvasMargin设置了没效果
跑demo,ram不断上涨,无法释放
用户发送的弹幕显示在上下,或者中间(或者是某行),,,由用户指定,请问是否提供了这样的接口呢
是否有循环播放的 feature?如果有的话怎么设置?
我现在有个功能是用户可以关闭弹幕或者再次开启弹幕,但是我直接用stop然后再start弹幕就不再出现了。请问要怎么去做呢,谢谢!
import UIKit
class BarrageViewController: UIViewController {
let renderer = BarrageRenderer.init()
var timer: Timer?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.addSubview(renderer.view)
renderer.canvasMargin = UIEdgeInsetsMake(10, 10, 10, 10)
renderer.view.isUserInteractionEnabled = true
view.sendSubview(toBack: renderer.view)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
renderer.start()
let safeObj = NSSafeObject.init(object: self, with: #selector(BarrageViewController.autoSendBarrage))
if #available(iOS 10.0, *) {
timer = Timer.scheduledTimer(timeInterval: 0.5, target: safeObj!, selector: #selector(NSSafeObject.excute), userInfo: nil, repeats: true)
} else {
// Fallback on earlier versions
}
}
func autoSendBarrage() {
let spriteNumber = renderer.spritesNumber(withName: nil)
print("当前屏幕的弹幕数量: \(spriteNumber)")
if spriteNumber < 100 {
renderer.receive(walkTextSpriteDescription(withDirection: BarrageWalkDirection.R2L, side: BarrageWalkSide.left))
renderer.receive(floatingTextSpriteDescriptor(withDirection: BarrageWalkDirection.B2T, side: BarrageFloatSide.center))
}
}
func walkTextSpriteDescription(withDirection direction: BarrageWalkDirection, side: BarrageWalkSide) -> BarrageDescriptor {
let descriptor = BarrageDescriptor()
descriptor.spriteName = "walk"
descriptor.params["attributedText"] = NSAttributedString.init(string: "过场文字: \(index = index + 1)", attributes: [NSForegroundColorAttributeName: UIColor.red, NSFontAttributeName: UIFont.systemFont(ofSize: 20)])
descriptor.params["speed"] = NSNumber.init(value: 1.0)
descriptor.params["direction"] = NSNumber.init(value: direction.rawValue)
descriptor.params["side"] = NSNumber.init(value: side.rawValue)
descriptor.params["clickAction"] = {
print("click")
}
return descriptor
}
var index = 0
func floatingTextSpriteDescriptor(withDirection direction: BarrageWalkDirection, side: BarrageFloatSide) -> BarrageDescriptor {
let descriptor = BarrageDescriptor()
descriptor.spriteName = "floating"
descriptor.params["text"] = "浮动文字: \(index = index + 1)"
descriptor.params["textColor"] = UIColor.red
descriptor.params["duration"] = NSNumber.init(value: 3)
descriptor.params["fadeInTime"] = NSNumber.init(value: 1)
descriptor.params["fadeOutTime"] = NSNumber.init(value: 1)
descriptor.params["direction"] = NSNumber.init(value: direction.rawValue)
descriptor.params["side"] = NSNumber.init(value: side.rawValue)
return descriptor
}
deinit {
renderer.stop()
}
}
`
/// 冒泡法排序,值越大越往后
- (void)stackSpirits
{
NSMutableArray * spirits = [NSMutableArray arrayWithArray:_spirits];
NSInteger num = spirits.count;
for (NSInteger i = 0; i < num - 1; i++) { //TODO: 这里如果num 换成 spirits.count, 会产生诡异的死循环
for (NSInteger j = i+1; j < num; j++) {
BarrageSpirit * spiritA = [spirits objectAtIndex:i];
BarrageSpirit * spiritB = [spirits objectAtIndex:j];
if (spiritA.z_index > spiritB.z_index) {
[spirits exchangeObjectAtIndex:i withObjectAtIndex:j];
}
}
}
_spirits = [spirits copy];
}
_spirits = [_spirits sortedArrayWith...]
sprits.count
是 NSUInteger
无符号整型如何改变一个从左向右的弹幕的纵坐标,我改变barragewalkspirit里面的几个参数后,所有都变成0了
加了快进快退功能之后,原来的暂停/恢复功能好像不行了
Some logic bugs in BarrageClock class.Here is my PR(#20 )
外部播放器seek 改变_predictedTime的值通过代理方法timeForBarrageRenderer: 传递到弹幕库,接着执行pause方法,时间好像乱了。
弹幕的播放与视频的播放同步
因为我显示弹幕的页面底下有个输入框,当激活输入框弹起键盘,可以明显的感觉到飘动的弹幕文字会明显卡顿一下,这个能解决吗?
我是复制的文件来编译为.a库的,这里少个引入,没什么大问题。
另外我想说我的效果是这样的:
从最左下方一行一行往上弹,发一个弹一个,最后发的在最下面,发一下把前面发的依次往上弹一个位置,就像聊天框那样的效果,不知道这个要用你的库怎么弄才好,给个思路吧。
移动速度快了,会闪烁,应该frame的x值一次跳几格
Undefined symbols for architecture x86_64:
"OBJC_CLASS$_BarrageDescriptor", referenced from:
objc-class-ref in AdvancedBarrageController.o
"OBJC_CLASS$_BarrageRenderer", referenced from:
objc-class-ref in AdvancedBarrageController.o
"OBJC_CLASS$_BarrageWalkTextSprite", referenced from:
objc-class-ref in AdvancedBarrageController.o
OBJC_CLASS$_BarrageWalkImageTextSprite in BarrageWalkImageTextSprite.o
"OBJC_CLASS$_MLEmojiLabel", referenced from:
objc-class-ref in BarrageWalkImageTextSprite.o
"OBJC_METACLASS$_BarrageWalkTextSprite", referenced from:
OBJC_METACLASS$_BarrageWalkImageTextSprite in BarrageWalkImageTextSprite.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
下载整个工程,pod update之后再运行提示这个错误:
ld: library not found for -lBarrageRenderer
frameworks中的.a文件是红色的
现在默认第一轨道在顶部,第一条弹幕就是从最上面出来,有设置让第一个弹幕从最下面出来的方法吗?
/// 更新逻辑时间系统
- (void)updateTime
{
NSDate * currentDate = [NSDate date];
self.time += [currentDate timeIntervalSinceDate:_previousDate] * self.speed;
_previousDate = currentDate;
}
这里每帧都会运行,构造 NSDate
开销可能比较大,只记时间戳可能好点
start之后会报 -[_SwiftTypePreservingNSNumber length]: unrecognized selector sent to instance 0x60000043db80的错误,看了半天不太好定位具体的位置。。。。
你好,当弹幕的展示区域较小,或者弹幕精灵的速度随机,或者某个时间段弹幕精灵的数量较多,都有一定概率出现某些弹幕精灵重叠在一起的情况,尽管可以通过spritesNumberWithName来限制精灵数量,但重叠的情况仍然会出现,求解决方案
demo中都是自上向下排布,能否改改成自下向上?
给的方法无效. 如果底层视图有手势,则不响应点击事件.
最近在做直播的项目,恰好找到您这个BarrageRenderer,非常高兴,现在我想模仿其他App(inke)的弹幕功能,就是弹幕是在收到socket时动态产生,弹幕主题由用户头像、用户昵称、用户发言内容组成,要求用户头像可以点击,进入用户的个人主页,现在想请教下,这个能否用BarrageRenderer实现,并说下大致思路;或者自己写一个view,然后动画从右至左,然后解决复用;哪种比较好?
参考你demo中的图文混排弹幕继承于 BarrageWalkTextSprite 类,并且覆盖 - (UIView *)bindingView
和 - (CGSize)size 方法来实现自定义图文混排弹幕,demo中是直接 self.text 获取要展示的文本,但是当我文本较多并且有图片之类的元素该如何传值到自定义的这个类中并在 bindingView 中进行计算设置。
如果播放视频到15s,快退5s,这时是10s的时候。之前10s-15s播放过的弹幕不会再播放吗,需要再等到视频15s的时候才能继续播弹幕?
如果要实现10s-15s的时候播放快退前播放过的弹幕,应该怎么处理这块逻辑?
如果要对弹幕的label加入点击事件该怎么做?
请教图文混排问题:
我在descriptor.params里加入了attributedText字段,弹幕中无法显示。
是否需要进行其他设置?
当我设置弹幕view的edges之后,比如底部留下1/3的位置不显示,当横屏下弹幕数量较多,我切回竖屏的时候,屏幕上的弹幕会被切,view的布局更新了,但是弹幕本身的布局还是横屏的,就会被view的边缘砍到。
另:有没有灵活的改变字体大小的方法呢?
另:每次load都会导致所有弹幕全部从当前时间加载,而不会按照播放时间加载~descriptor能提供timestamp参数么,当前用的是delay
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.