2

I currently have a mediaplayer that is given a streamable datasource. I have two test devices: HTC Thunderbolt and a Samsung Galaxy SII Skyrocket.

The HTC device is able to stream the files perfectly fine; however, the galaxy sII cannot at all, and gives me a bunch of media player error codes.

I am implementing everything related to the media player properly...however, i can't get my head around this issue...how come it'll work on one phone but not the other? its the same link.

Any ideas? Logs from the devices below. Can post my code if necessary as well.

Thanks!

Log from the HTC device:

06-25 18:19:23.192: D/MainAudioService(23564): next song is: http://soundcloud.com/stopdroprave/chromeo-night-by-night/download/s-bpPu1
06-25 18:19:26.675: W/MediaPlayer(23564): info/warning (1, 902)
06-25 18:19:28.497: D/dalvikvm(23564): GC_EXTERNAL_ALLOC freed 515K, 50% free 3544K/7047K, external 477K/989K, paused 22ms
06-25 18:19:31.250: D/MainAudioService(23564): Song length in minutes is: -6:5
06-25 18:19:31.250: D/MediaPlayer(23564): start() in
06-25 18:19:31.250: D/MediaPlayer(23564): start() out
06-25 18:19:31.310: I/MediaPlayer(23564): Info (1,902)
06-25 18:19:31.310: D/MainAudioService(23564): On Info in MP: 1and 902
06-25 18:19:50.909: D/MediaPlayer(23564): stop() in
06-25 18:19:50.919: D/MediaPlayer(23564): stop() out
06-25 18:19:50.919: D/MediaPlayer(23564): reset() in
06-25 18:19:50.929: D/MediaPlayer(23564): reset() out
06-25 18:19:50.939: D/MainAudioService(23564): next song is: http://soundcloud.com/stopdroprave/subvibe-mizukis-last-chance/download/s-Jaezp
06-25 18:19:55.433: W/MediaPlayer(23564): info/warning (1, 902)
06-25 18:19:58.656: D/dalvikvm(23564): GC_EXTERNAL_ALLOC freed 503K, 57% free 3099K/7047K, external 1102K/1614K, paused 45ms
06-25 18:20:00.338: D/MainAudioService(23564): Song length in minutes is: -6:39
06-25 18:20:00.338: D/MediaPlayer(23564): start() in
06-25 18:20:00.338: D/MediaPlayer(23564): start() out
06-25 18:20:00.408: I/MediaPlayer(23564): Info (1,902)

Log from the SGSII:

06-25 18:27:32.797: E/MediaPlayer(24277): stop called in state 0
06-25 18:27:32.797: E/MediaPlayer(24277): error (-38, 0)
06-25 18:27:32.807: D/MainAudioService(24277): next song is: http://soundcloud.com/stopdroprave/doctor-p-watch-out-crazes-locd/download/s-qQhJP
06-25 18:27:32.807: E/MediaPlayer-JNI(24277): setDataSource: outside path in JNI is �x@
06-25 18:27:33.498: E/MediaPlayer(24277): error (1, -2147483648)
06-25 18:27:33.498: E/MediaPlayer(24277): Error (1,-2147483648)
06-25 18:27:33.498: D/MainAudioService(24277): Error in MP: 1 and -2147483648
06-25 18:27:33.498: E/MediaPlayer(24277): stop called in state 0
06-25 18:27:33.498: E/MediaPlayer(24277): error (-38, 0)
06-25 18:27:33.508: D/MainAudioService(24277): next song is: http://soundcloud.com/stopdroprave/digitalism-circle-eric-prydz/download/s-XlYFv
06-25 18:27:33.508: E/MediaPlayer-JNI(24277): setDataSource: outside path in JNI is �x@
06-25 18:27:34.149: E/MediaPlayer(24277): error (1, -2147483648)
06-25 18:27:34.149: E/MediaPlayer(24277): Error (1,-2147483648)
06-25 18:27:34.149: D/MainAudioService(24277): Error in MP: 1 and -2147483648

EDIT:

here is where i set the datasource....

SdrPlaylist p = mPlaylist.get(currentNum);

            String path = p.songUrl;

            artistInfo = p.songName;
            nextSong = Toast.makeText(getApplicationContext(),
                    "Buffering Next Song...", Toast.LENGTH_LONG);
            nextSong.setGravity(Gravity.TOP, 0, 110);
            nextSong.show();

            try {
                Log.d(TAG, "next song is: " + path);

                mediaPlayer.setDataSource(path);

                mediaPlayer.prepareAsync();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
Splitusa
  • 1,181
  • 7
  • 31
  • 51
  • try adding the code where you set the datasource of your media player – Raykud Jun 26 '12 at 00:01
  • just added the datasource code part – Splitusa Jun 26 '12 at 00:06
  • I tried same links as you on SGS2 and none of them worked. E.g this link; http://soundcloud.com/fanu/d-b-show-with-fanu-docius-on/download worked ok. Can't tell what's wrong with download links you're using though. – harism Jun 26 '12 at 00:18
  • @harism and Splitusa I'm having the same issue about streaming the mp3 file with Android Media Player, it works in every single device but not in Samsung devices. I tested with a couple of devices but none of them worked. Did you learn the reason and find a work around ? Thanks. – osayilgan Apr 29 '13 at 10:16

2 Answers2

2

The docs for MediaPlayer state:

For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.

So I would start by trying that. You'll need to use the OnPreparedListener to call start() for you instead of assuming that prepare is finished after it returns.

private MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer arg0) {
        mp.start();

    }
});

mp.reset(); //<--- you probably shouldn't need this here.
mp.setDataSource(soundUri);
mp.prepareAsync();

That way you will be guaranteed not to be calling start() before the MediaPlayer is prepared.

If you are still having trouble after this change my next guess is that it is codec related. Media playback on android is a bit finicky, and that is doubly true for streaming Media. What type of file are you trying to play?

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • perhaps you could help me - I'm doing everything you're suggesting here, but my stream doesn't work on a Samsung S3 device - all other Samsung devices (S4, Note I & II, SII, SIII mini, Nexus phone, Music) plays the stream perfectly. My question here: http://stackoverflow.com/questions/16672568/mediaplayer-error-1-1004-aka-media-error-io-trying-to-stream-music-on-samsun – marienke May 22 '13 at 11:52
0

as it seems to be an issue of you setting the datasource of your mediaplayer here is how it should be done:

private MediaPlayer mp = new MediaPlayer();
mp.reset();
mp.setDataSource(soundUri);
mp.prepare();
mp.start();

or you could check the full answer here: https://stackoverflow.com/a/9061259/1084764

Community
  • 1
  • 1
Raykud
  • 2,488
  • 3
  • 21
  • 41
  • 1
    that's how i have it set up...that doesn't explain why it works on one device but not the other... – Splitusa Jun 26 '12 at 00:07
  • It's a bit surprising if all 4 songs play on HTC as 3 of them seem to have been removed; http://soundcloud.com/stopdroprave/ . – harism Jun 26 '12 at 00:29
  • all of the songs play on the HTC. the reason why they aren't visible is because they are set to private. the song you streamed is set to public, which is why it works. – Splitusa Jun 26 '12 at 00:31
  • Ah, I see. Sorry I'm not that familiar with SoundCloud to know there was a privacy setting. Anyway, song http://soundcloud.com/stopdroprave/subvibe-mizukis-last-chance/download played ok on my SGS2 (the only public one) once I dropped the trailing id. – harism Jun 26 '12 at 00:33
  • yeah that's the only one that also streams for me on my SGS2...any ideas why the other links stream on the HTC but not the SGS2? – Splitusa Jun 26 '12 at 00:38
  • so the private links are the ones that aren't beeing played? If so then it might be a security reason regarding SGS2 – Raykud Jun 26 '12 at 00:45
  • I did some WireSharking on emulator and it seems so that for some reason private links are redirected to m.soundcloud.com login or error page while public ones start download immediately. – harism Jun 26 '12 at 00:59