Using AVPlayer in iOS can you know the current .ts file or the current timestamp from the encoder?

北城以北 提交于 2019-12-04 10:56:56

You just have to:

  1. Subclass NSURLProtocol with a class you implement (refer to NSURLProtocol Class Reference on Apple to see how it works). You have a method coming with NSURLProtocol in which you can see intercepted request

(BOOL)canInitWithRequest:(NSURLRequest *)request.

Just log you request inside it and return NO, because you just want to log it and not treating it by launching startLoading method, another method from NSURLProtocol API.

  1. Once this is done, you have to register your NSURLProtocol into didFinishLaunching method into your AppDelegate.m / .swift (whatever...) by adding this instruction: NSURLProtocol.registerClass(MySubclassProtocol)

  2. Launch your player, you should see normally all requests logged into your debug console.

Hope it helps

NSLog(@"%@", [[mPlayer currentItem] currentDate ]);

A slight update on this subject. A little trick to get more information about the current .ts the AVPlayer is loading, is to register in didFinishLaunching method of AppDelegate, an NSURLProtocol object

-> NSURLProtocol.registerClass(MyURLProtocol)

This gives you the opportunity to see all requests transiting into your app, and consequently, to see when a segment is loaded by the player :

2015-06-04 10:57:13.172 MyApp[924:310b] Got request for URL: http://livestream.net/channel/channel.isml/events(1433260048)/channel-audio_1=128000-video=1600000.m3u8 2015-06-04 10:57:13.182 MyApp[924:6a07] Got request for URL: http://livestream.net/channel/channel.isml/events(1433260048)/channel-audio_1=128000-video=1600000-143341543.ts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!