stream music in android using mobile data and not wifi

345 views Asked by At

I have developed a music app that streams from an url. It seems to work fine on wifi connection but does not buffer on mobile 3G (i.e the song does not play).The code inside onClickListener for play/pause button is-

private OnClickListener TumHiHo = new OnClickListener() {

    @Override
    public void onClick(View v) {

        if (!playPauseTumHiHo) {
            tumhihobtn.setBackgroundResource(R.drawable.button_pause);
            if (initialStartTumHiHo)
            {  mediaPlayer.stop();
            mediaPlayer.reset();
            initialStartSunRahaHaiNa=true;
            initialStartTumHiHo=false;
            new Player()
                        .execute("http://sound30.mp3slash.net/indian/aashiqui2/[Songs.PK]%20Aashiqui%202%20-%2001%20-%20Tum%20Hi%20Ho.mp3");
            loadDocTumHiHo();
            chkStatus();

            }else {
                if (!mediaPlayer.isPlaying())
                    mediaPlayer.start();
            }
            playPauseTumHiHo = true;
        } else {
            tumhihobtn.setBackgroundResource(R.drawable.button_play);
            if (mediaPlayer.isPlaying())
                mediaPlayer.pause();
            playPauseTumHiHo = false;
        }
    }
};

The chkStatus() is to test whether user is using mobile data or wifi.

Manifest file has-

 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The logcat shown is as-

12-12 22:22:23.906: V/MediaPlayer(400): stop
12-12 22:22:23.906: E/MediaPlayer(400): stop called in state 0
12-12 22:22:23.906: V/MediaPlayer(400): message received msg=100, ext1=-38, ext2=0
12-12 22:22:23.906: E/MediaPlayer(400): error (-38, 0)
12-12 22:22:23.906: V/MediaPlayer(400): callback application
12-12 22:22:23.906: V/MediaPlayer(400): back from callback
12-12 22:22:23.906: V/MediaPlayer-JNI(400): reset
12-12 22:22:23.906: V/MediaPlayer(400): reset
12-12 22:22:49.171: V/MediaPlayer-JNI(400): stop
12-12 22:22:49.176: V/MediaPlayer(400): stop
12-12 22:22:49.176: E/MediaPlayer(400): stop called in state 1
12-12 22:22:49.176: V/MediaPlayer(400): message received msg=100, ext1=-38, ext2=0
12-12 22:22:49.176: E/MediaPlayer(400): error (-38, 0)
12-12 22:22:49.176: V/MediaPlayer(400): callback application
12-12 22:22:49.176: V/MediaPlayer(400): back from callback
12-12 22:22:49.176: V/MediaPlayer-JNI(400): reset
12-12 22:22:49.176: V/MediaPlayer(400): reset
12-12 22:22:49.241: W/ResourceType(400): Failure getting entry for 0x010802c1 (t=7 e=705) in package 0 (error -75)
12-12 22:22:49.251: D/dalvikvm(400): GC_CONCURRENT freed 55K, 11% free 10620K/11847K, paused 16ms+7ms, total 51ms
12-12 22:22:49.306: V/MediaPlayer(400): setVideoSurfaceTexture
12-12 22:22:49.306: V/MediaPlayer(400): prepare
12-12 22:22:52.266: V/MediaPlayer(400): message received msg=100, ext1=1, ext2=-1004
12-12 22:22:52.266: E/MediaPlayer(400): error (1, -1004)
12-12 22:22:52.266: V/MediaPlayer(400): signal application thread
12-12 22:22:52.266: V/MediaPlayer(400): prepare complete - status=1
12-12 22:22:52.281: W/System.err(400): java.io.IOException: Prepare failed.: status=0x1
12-12 22:22:52.281: W/System.err(400):  at android.media.MediaPlayer.prepare(Native Method)
12-12 22:22:52.291: W/System.err(400):  at com.bignerdranch.android.lyrischemusik1.MusikActivity4$Player.doInBackground(MusikActivity4.java:235)
12-12 22:22:52.291: W/System.err(400):  at com.bignerdranch.android.lyrischemusik1.MusikActivity4$Player.doInBackground(MusikActivity4.java:1)
12-12 22:22:52.296: W/System.err(400):  at android.os.AsyncTask$2.call(AsyncTask.java:287)
12-12 22:22:52.296: W/System.err(400):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-12 22:22:52.296: W/System.err(400):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-12 22:22:52.296: W/System.err(400):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
12-12 22:22:52.296: W/System.err(400):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-12 22:22:52.296: W/System.err(400):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-12 22:22:52.301: W/System.err(400):  at java.lang.Thread.run(Thread.java:856)
12-12 22:22:52.346: D/Prepared(400): //false
12-12 22:22:52.346: V/MediaPlayer-JNI(400): start
12-12 22:22:52.346: V/MediaPlayer(400): start
12-12 22:22:52.346: E/MediaPlayer(400): start called in state 0
12-12 22:22:52.346: V/MediaPlayer(400): message received msg=100, ext1=-38, ext2=0
12-12 22:22:52.346: E/MediaPlayer(400): error (-38, 0)
12-12 22:22:52.346: V/MediaPlayer(400): callback application
12-12 22:22:52.346: V/MediaPlayer(400): back from callback
12-12 22:22:52.401: E/MediaPlayer(400): Error (-38,0)
12-12 22:22:52.406: V/MediaPlayer-JNI(400): stop
12-12 22:22:52.406: V/MediaPlayer(400): stop
12-12 22:22:52.406: E/MediaPlayer(400): stop called in state 0
12-12 22:22:52.406: V/MediaPlayer(400): message received msg=100, ext1=-38, ext2=0
12-12 22:22:52.406: E/MediaPlayer(400): error (-38, 0)
12-12 22:22:52.406: V/MediaPlayer(400): callback application
12-12 22:22:52.406: V/MediaPlayer(400): back from callback
12-12 22:22:52.406: V/MediaPlayer-JNI(400): reset
12-12 22:22:52.406: V/MediaPlayer(400): reset

I don't know whether the problem is with my mobile's network or with the app. If it's the app please let me know where I might be going wrong. Thanks in advance.

1

There are 1 answers

0
Bhavik Mehta On

Try replacing this code with your method

new Player().execute("http://sound30.mp3slash.net/indian/aashiqui2/[Songs.PK] Aashiqui 2 - 01 - Tum Hi Ho.mp3");