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

3k views Asked by At

Since we are unable to get Closed caption data or subtitle data out of the AVPlayer, we are looking at other trigger methods, such as timecode or at least the knowledge of the .ts file that is currently active. I couldn't find anything in the documentation and the CMTime from the player doesn't give me the timecode that is embedded in the m3u8 files.

NSLog(@"%f", CMTimeGetSeconds([mPlayer currentTime] ) );

is not what I'm looking for.

#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:562
#EXT-X-PROGRAM-DATE-TIME:2020-10-23T14:18:59+08:00
#EXTINF:10,
http://aedsgios1-i.akamaihd.net/hls/live/204775/test1-p/mobile600/Seg_102320_124459_1/mobile600_102320_124459_562.ts
#EXT-X-PROGRAM-DATE-TIME:2020-10-23T14:19:09+08:00
#EXTINF:10,

The EXT-X-PROGRAM-DATE-TIME is what I'm looking to know, or at least the name of the .ts file that is active.

Thanks!

3

There are 3 answers

4
angelfilm entertainment On BEST ANSWER

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

1
lolodiv On

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

1
lolodiv On

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