From 0715f84b1a4384e09afdd77b281d55c432c6adff Mon Sep 17 00:00:00 2001 From: andreivolgin Date: Mon, 20 Jan 2020 09:54:00 -0500 Subject: [PATCH] Enable playing local files in iOs. --- ios/Classes/AudioPlayer.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ios/Classes/AudioPlayer.m b/ios/Classes/AudioPlayer.m index b4b159a..da429b8 100644 --- a/ios/Classes/AudioPlayer.m +++ b/ios/Classes/AudioPlayer.m @@ -155,7 +155,16 @@ [[NSNotificationCenter defaultCenter] removeObserver:_endObserver]; _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 forKeyPath:@"status" options:NSKeyValueObservingOptionNew