Reputation: 103
I am playing an Audio file from a URL directly. Here is the Code :
try {
Uri uri = Uri.parse("https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3");
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(getActivity(), uri);
player.prepare();
player.start();
} catch(Exception e) {
System.out.println(e.toString());
}
LogCat :
W/MediaPlayer: Couldn't open https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3: java.io.FileNotFoundException: No content provider: https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3
Upvotes: 0
Views: 1753
Reputation: 1150
Check the URL path is accessible from the browser directly.
change the order of api calls
player.setDataSource(getActivity(), uri);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.prepare();
try this.
Upvotes: 1