I've been trying so hard to develop an Internet radio Streaming app, but all I get it some force closes or errors. Steps I've taken,
- I've read the MediaPlayer Documentation here.
- I've also read the already available solutions here.
- I've also searched google for any solutions but found none.
Here is my code:
MainActivity:
private Button pbutton;
private MediaPlayer mediaPlayer;
pbutton = findViewById(R.id.button_play);
pbutton.setEnabled(false);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource("http://streams.abidingradio.org:7800/1");
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
pbutton.setEnabled(true);
}
});
pbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mediaPlayer.start();
}
});
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I run this code, MediaPlayer is not getting prepared. And it throws the following errors: click here for the full log the main errors are:
failed to init data from source
MediaPlayerNative: error (1, -2147483648)
MediaPlayer: Error (1,-2147483648)
I've been dealing with this problem for almost three days but still haven't found a solution. I can also assure that the link of the audio stream is working perfectly.
Any help would be greatly appreciated!
Thank you.