0
votes

I want to play vod.m3u8 file which is stored inside app home directory. vod.m3u8 file contains index0, index1, etc... in it. .ts file is physically present in directory.

#EXTM3U

#EXT-X-VERSION:0

#EXT-X-TARGETDURATION:1

#EXT-X-PLAYLIST-TYPE:VOD

#EXT-X-MEDIA-SEQUENCE:0

#EXTINF:11,

index0.ts

#EXTINF:10,

index1.ts

#EXTINF:5,

index2.ts

#EXTINF:5,

index4.ts

#EXTINF:10,

index5.ts

#EXTINF:10,

index6.ts

#EXTINF:5,

index7.ts

#EXT-X-ENDLIST

Following is my code to play video

-(void)playLocalVideo
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"vod" 
  ofType:@"m3u8"];
NSURL *url = [[NSURL alloc] initFileURLWithPath: path];
AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
anItem = [AVPlayerItem playerItemWithAsset:asset];
player = [AVPlayer playerWithPlayerItem:anItem];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:player];
layer.frame = self.view.layer.bounds;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 320, 250)];
[view.layer addSublayer:layer];
[self.view addSubview:view];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary *)change context:(void *)context
{
 if (object == player && [keyPath isEqualToString:@"status"]) {
    if (player.status == AVPlayerStatusFailed) {
        NSLog(@"AVPlayer Failed");
    } else if (player.status == AVPlayerStatusReadyToPlay) {
        NSLog(@"AVPlayer Ready to Play");
        [player play];
    } else if (player.status == AVPlayerItemStatusUnknown) {
        NSLog(@"AVPlayer Unknown");
    }
   }
 }

AVPlayer status is AVPlayer Ready To Play, But it never plays video. If i play any mp4 video then it's playing,but not vod.m3u8 file.

Plz any help.

1
As mentioned here (forums.developer.apple.com/thread/69357) you can not get content of m3u8 file locally. Have you got any luck around it. I have also messed in same issue. - Rahul Verma

1 Answers

0
votes

The issue is probably in the values in your M3U8 files.

Your target duration should describe the maximum playback length of your .TS segments. Your EXTINF says the segments are up to 10 seconds, so you should set #EXT-X-TARGETDURATION:11 instead of 1 .

You probably need a real value for your EXT-X-VERSION. See https://developer.apple.com/library/archive/qa/qa1752/_index.html . Set a minimum value of 2.

An HLS package usually starts with a master manifest that points to variant playlists such as your VOD.m3u8, so you might try creating a master.m3u8 that points to your VOD.m3u8 rather than trying to play your variant playlist directly.

In general, you probably want to start with a working HLS sample and then edit it down to match the properties of your segments, rather than trying to build from scratch and guess at which values are important.