react-native-audioplayer
react-native-audioplayer copied to clipboard
URI as a source
Is there a support using an URI? thanks
There is none. You can make it work pretty easily for iOS though:
Install react-native-audioplayer as prescribed on the docs (https://github.com/andreaskeller/react-native-audioplayer#installation).
Add this before @end
in RNAudioPlayer.h:
@property (strong, nonatomic) AVPlayer *audioPlayerURL;
This before @end
in RNAudioPlayer.m:
RCT_EXPORT_METHOD(playFromURL:(NSString *)url)
{
NSURL *soundURL=[NSURL URLWithString:url];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL: soundURL];
self.audioPlayerURL = [AVPlayer playerWithPlayerItem:playerItem];
[self.audioPlayerURL play];
self.audioPlayerURL.actionAtItemEnd = AVPlayerActionAtItemEndNone;
}
And add this in AudioPlayer object in AudioPlayer.js in node_modules/react-native-audioplayer:
playFromURL(fileName: string) {
RNAudioPlayer.playFromURL(fileName);
}
You should now be able to pass a URL to AudioPlayer instance in your React Native code: AudioPlayer.playFromURL("http://example.com/song.mp3")
N.B. You will have to recompile from Xcode for your objective-c code to work.