2

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:

  • If using blocking prepare(), it fails with IOException
  • If using non-blocking prepareAsync(), it fails and onErrorListener triggers (no exception is raised).

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:

  • Using pepareAsync() and onPreparedListener to call start()
  • Calling reset() on Media Player
  • Setting the data source through Uri.parse()
  • Obtaining audio focus from Audio Manager

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();
}
}
assen.totin
  • 41
  • 1
  • 8

1 Answers1

0

This is normally because the stream type is not supported by the device you're using. Have you tried a simple MP3 stream?

Geobits
  • 22,218
  • 6
  • 59
  • 103
  • How can it possibly that 'stream type is not supported by the device'? If API 7 in emulator play it, how can API 15 on hardware 'not support it'? – assen.totin Mar 07 '13 at 20:50
  • Your PC probably has more supported codecs than your phone. It has nothing to do with API level, it's what the manufacturers decided to put in it. Google the error message, it's the most common explanation I found for it. – Geobits Mar 07 '13 at 20:52
  • The API 15 testdbed is Android 4.0.3 kernel version 3.0.8. I tried the same app on another device, HTC Deside C phone with 4.0.3 but kernel version 3.0.16 - and it works there. So I might be dealing with some bad Adndoid build on my original device (it uses vendor-supplied Android build)? It there a place (site repository) to check for this? – assen.totin Mar 07 '13 at 20:53
  • I doubt it's a "bad build", but I guess it's possible. More likely the format is not one of the ones guaranteed to work on all devices, and is only supported by certain devices. Check [this link](http://developer.android.com/guide/appendix/media-formats.html). – Geobits Mar 07 '13 at 20:57
  • Input #0, mp3, from 'radiojukebox-low': Duration: 00:00:14.87, start: 0.000000, bitrate: 64 kb/s Stream #0:0: Audio: mp3, 44100 Hz, stereo, s16, 64 kb/s – assen.totin Mar 07 '13 at 21:06
  • And I strongly doubt that MediaPlayer in emulator is using the codecs from my OS... If that was the case, I would have been able to play in AAC in emulator with API 7 which in fact is not possible (AAC support only works in the latest API 17). – assen.totin Mar 07 '13 at 21:07
  • That is a pretty standard format, assuming the network protocol is standard. Odd that you can't do AAC in emulator, though, because mine does. (It does at API 8 at least, haven't tested 7, but it's not "officially" supported until 11). Not sure at this point, then. Hope you can figure it out. – Geobits Mar 07 '13 at 21:11