diff --git a/AudioPlayer.js b/AudioPlayer.js index f2d221b..c4fc588 100644 --- a/AudioPlayer.js +++ b/AudioPlayer.js @@ -7,6 +7,10 @@ var AudioPlayer = { play(fileName: string) { fileName = Platform.OS === 'ios' ? fileName : fileName.replace(/\.[^/.]+$/, ""); RNAudioPlayer.play(fileName); + }, + + playFromURL(fileName: string) { + RNAudioPlayer.playFromURL(fileName); } }; diff --git a/RNAudioPlayer.h b/RNAudioPlayer.h index 4eb3b9b..c5315e9 100644 --- a/RNAudioPlayer.h +++ b/RNAudioPlayer.h @@ -4,5 +4,6 @@ @interface RNAudioPlayer : NSObject @property (strong, nonatomic) AVAudioPlayer *audioPlayer; +@property (strong, nonatomic) AVPlayer *audioPlayerURL; @end diff --git a/RNAudioPlayer.m b/RNAudioPlayer.m index 8572672..1bf81a8 100644 --- a/RNAudioPlayer.m +++ b/RNAudioPlayer.m @@ -18,4 +18,13 @@ @implementation RNAudioPlayer [self.audioPlayer play]; } +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; +} + @end diff --git a/package.json b/package.json index a188300..85f9bf7 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "react-native-audioplayer", + "name": "react-native-stream-audio-from-url", "version": "0.2.0", "description": "Small audio player library for react native", "main": "AudioPlayer.js", @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git@github.com:andreaskeller/react-native-audioplayer.git" + "url": "https://github.com/tbinetruy/react-native-audioplayer" }, "keywords": [ "react-component", @@ -17,6 +17,6 @@ "android", "audioplayer" ], - "author": "Andreas Keller (https://github.com/andreaskeller)", + "author": "Thomas Binetruy and Andreas Keller (forked from https://github.com/andreaskeller/react-native-audioplayer)", "license": "MIT" }