I would like to create an app on Wear OS which plays back an online stream. The following code works fine under Android but not on Android Wear OS. Does anyone has an idea, why I get the Prepare failed status.
MediaPlayer mediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
mTextView = binding.text;
String url = "....the url like http://streamserver.com/stream";
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioAttributes(new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build());
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare(); //here the Exception takes place after around 15 seconds of waiting.
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
If I change the code to mediaPlayer.prepareAsync(); with mediaPlayer.setOnPreparedListener(...) it also doesn't work. Logcat shows: E/MediaPlayerNative: error (1, -2147483648)
Any idea, why it doesn't work on Wear OS but works on android?
Thanks
Jason