Merge pull request #26 from volgin/master

Enable playing local files in iOS.
This commit is contained in:
ryanheise 2020-01-21 02:07:02 +11:00 committed by GitHub
commit ad88e986f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -155,7 +155,16 @@
[[NSNotificationCenter defaultCenter] removeObserver:_endObserver]; [[NSNotificationCenter defaultCenter] removeObserver:_endObserver];
_endObserver = 0; _endObserver = 0;
} }
AVPlayerItem* playerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:url]];
AVPlayerItem *playerItem;
//Allow iOs playing both external links and local files.
if ([url hasPrefix:@"file://"]) {
playerItem = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:[url substringFromIndex:7]]];
} else {
playerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:url]];
}
[playerItem addObserver:self [playerItem addObserver:self
forKeyPath:@"status" forKeyPath:@"status"
options:NSKeyValueObservingOptionNew options:NSKeyValueObservingOptionNew