我开发了一个从url流式传输的音乐应用程序。它似乎在wifi连接上工作得很好,但在移动3G上没有缓冲(即歌曲不播放)。用于播放/暂停按钮的ClickListener内的代码是-
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;
}
}
};
chkStatus()用于测试用户是在使用移动数据还是wifi。
清单文件具有-
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
显示的logcat为-
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
我不知道问题出在我手机的网络上还是应用程序上。如果是应用程序,请告诉我哪里可能出了问题。提前谢谢。
尝试用您的方法替换此代码
new Player().execute("http://sound30.mp3slash.net/indian/aashiqui2/[Songs.PK] Aashiqui 2 - 01 - Tum Hi Ho.mp3");