结果是前2首歌曲播放得很好,但其他歌曲没有播放,而且它几乎没有播放就到了最后一首歌!
播放流的代码(可行):
private void PlayStream(String url)
{
try
{
mediaPlayer.setDataSource(url);
}
catch (IllegalArgumentException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaPlayer.setOnPreparedListener(Canzone.this);
try
{
mediaPlayer.prepareAsync();
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
progressBar.setVisibility(ProgressBar.VISIBLE);
progressBar.setProgress(0);
progressBar.setMax(duration);
new Thread(this).start();
}
SETONCOMPLETELISTENER的规范:
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
i++;
if(i<10)
{
classifica.setText("Canzoni riprodotte: "+String.valueOf(i+1)+"/10 \nPunteggio: "+punteggio);
mp.stop();
Log.d("MPLAY", "MP Stopped");
mp.reset();
Log.d("MPLAY", "MP Reset");
PlayStream(dieciCanzoni.get(i).get(0));
tv.setText(dieciCanzoni.get(i-1).get(1) + "\n" + dieciCanzoni.get(i-1).get(2));
new DownloadImageTask((ImageView) findViewById(R.id.albumImage)).execute(dieciCanzoni.get(i-1).get(4));
iv.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse(dieciCanzoni.get(i-1).get(3)));
startActivity(intent);
}
});
}
else
{
FineRound();
}
}
});
logcat的:
11-13 19:42:47.835: D/MPLAY(1981): MP Started
11-13 19:43:17.915: D/MPLAY(1981): MP Stopped
11-13 19:43:17.935: D/MPLAY(1981): MP Reset
11-13 19:43:17.940: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:17.990: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:17.990: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:17.995: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:17.995: D/MPLAY(1981): MP Stopped
11-13 19:43:18.235: D/MPLAY(1981): MP Reset
11-13 19:43:18.235: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:18.270: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:18.285: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:18.285: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:18.295: D/MPLAY(1981): MP Stopped
11-13 19:43:18.450: D/MPLAY(1981): MP Reset
11-13 19:43:18.450: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:18.470: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:18.475: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:18.475: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:18.475: D/MPLAY(1981): MP Stopped
11-13 19:43:18.690: D/MPLAY(1981): MP Reset
11-13 19:43:18.690: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:18.735: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:18.735: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:18.740: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:18.740: D/MPLAY(1981): MP Stopped
11-13 19:43:19.105: D/MPLAY(1981): MP Reset
11-13 19:43:19.105: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:19.185: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:19.185: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:19.190: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:19.190: D/MPLAY(1981): MP Stopped
11-13 19:43:19.680: D/MPLAY(1981): MP Reset
11-13 19:43:19.680: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:19.780: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:19.800: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:19.800: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:19.800: D/MPLAY(1981): MP Stopped
11-13 19:43:20.010: D/MPLAY(1981): MP Reset
11-13 19:43:20.015: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:20.130: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:20.130: E/MediaPlayer(1981): stop called in state 4
11-13 19:43:20.135: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:20.135: D/MPLAY(1981): MP Stopped
11-13 19:43:20.330: D/MPLAY(1981): MP Reset
11-13 19:43:20.330: E/MediaPlayer(1981): error (-38, 0)
11-13 19:43:20.365: E/MediaPlayer(1981): Error (-38,0)
11-13 19:43:22.105: D/MPLAY(1981): MP Started
11-13 19:43:25.590: W/IInputConnectionWrapper(1981): showStatusIcon on inactive InputConnection
11-13 19:43:25.615: D/OpenGLRenderer(1981): Flushing caches (mode 0)
11-13 19:43:26.140: D/OpenGLRenderer(1981): Flushing caches (mode 1)
答案 0 :(得分:0)
是的,我总能提供帮助。我也有这个错误,我的解决方案是检查ASROROID MEDIA PLAYER接收它的路径。所以要粘贴这段代码:
Log.d("MediaPlayer Datasource" , "The datasource is: " + url);
检查网址是否良好并包含扩展名。确保它不受域保护。
如果每件事都没问题,那就粘贴这段代码:
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mediaPlayer.start();
}
});
我知道你们都准备好了,但也许它不起作用。
答案 1 :(得分:0)
使用3GP视频文件,它将正常工作......