AVURLAsset cannot load with deleted file

I have a problem using AVURLAsset.

NSString * const kContentURL = @

"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
...

    NSURL *contentURL = [NSURL URLWithString:kContentURL];
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:contentURL
                                               options:nil];
    [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey]
                            completionHandler:^{
    ...
                               NSError *error = nil;
                               AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey
                                                                              error:&error];
    ...
    }

In the completion block, the status is AVKeyValueStatusFailed and the error message is "Can not Open". All the examples I've seen use a local file, so maybe the problem is with the remote file ...

Regards, Quentin

+5
source share
1 answer

You cannot directly create an AVURLAssetHTTP Live stream for a stream, as described in the Apple AV Foundation Programming Guide . You will need to create AVPlayerItemwith the URL of the stream and create AVPlayer with it

AVPlayerItem *pItem = [AVPlayerItem playerItemWithURL:theStreamURL];
AVPlayer *player = [AVPlayer playerWithPlayerItem:pItem];

AVURLAsset, .

1/ status

[playerItem addObserver:self forKeyPath:@"status" options:0 context:nil];

2/ observeValueForKeyPath:ofObject:change:context:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
                        change:(NSDictionary *)change context:(void *)context { 
    if ([keyPath isEqualToString:@"status"]) {
        AVPlayerItem *pItem = (AVPlayerItem *)object;
        if (pItem.status == AVPlayerItemStatusReadyToPlay) {
            // Here you can access to the player item asset
            // e.g.: self.asset = (AVURLAsset *)pItem.asset;
        }
    }   
}

EDIT:

+6

All Articles