I'm facing a weird problem related to Android, streaming and Media Player.
The actual app is quite complex, but I have put the simplest possible test case: a 'Hello, World' activity launches Media Player with a hard-coded URL. This works fine in Android emulator, both API level 7 (which is the minimum for the real app) and API level 17. However, the same app fails on a hardware device with API level 15 - Media Player fails during the prepare() call:
The failure always (blocking and non-blocking prepare) shows "Error (1,-2147483648)". Media Player docs have no such error code -2147483648 (0xffffffff).
The app has proper permission to access the Internet (android.permission.INTERNET) and the Internet connection of the device is working (the same app can download files from Internet).
This is not a codec issue - because the same stream can be played by the emulator and because any other stream fails in the same way on the hardware device.
Tried many other things of which none helped:
Hardware is working properly as the same device can play audio files from its storage using the Android built-in default audio player app.
I don't believe (much) in ghosts, but I'm kinda running out of other options. Anybody seen anything like this? The app working in emulator, but not on hardware?
Can anybody please try this code on a hardware device (I only have 1 Android device)?
public class MainActivity extends Activity {
private MediaPlayer mediaPlayer;
private String listen_url = "http://stream15.top-ix.org:80/radiojukebox-low";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mediaPlayer = new MediaPlayer();
//mediaPlayer.reset();
try {
mediaPlayer.setDataSource(listen_url);
//mediaPlayer.setDataSource(this, Uri.parse(listen_url));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
// We fail here!
e.printStackTrace();
}
mediaPlayer.start();
}
}
This is normally because the stream type is not supported by the device you're using. Have you tried a simple MP3 stream?
User contributions licensed under CC BY-SA 3.0