I am using Android\'s MediaPlayer to set up a URL stream in my application. I have tried several different posts to deal with the exit code and error: (1, -2147483648).
try with this code
Tested with real device Vivo V7+ Android 8.1.0
private MediaPlayer player;
String url = "http://199.180.75.118:80/stream"; //temp stream
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initializeMediaPlayer() {
player = new MediaPlayer();
player.setAudioAttributes( new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build());
try {
//change with setDataSource(Context,Uri);
player.setDataSource(this, Uri.parse(url));
player.prepareAsync();
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
//mp.start();
player.start();
}
});
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Make sure u defined the permission in manifest file
Manifest.xml
//.....
Ref :: https://developer.android.com/training/articles/security-config
The Network Security Configuration feature lets apps customize their network security settings in a safe, declarative configuration file without modifying app code. These settings can be configured for specific domains and for a specific app. The key capabilities of this feature are as follows:
The Network Security Configuration feature uses an XML file where you specify the settings for your app. You must include an entry in the manifest of your app to point to this file. The following code excerpt from a manifest demonstrates how to create this entry:
...
network_security_config.xml