我使用以下代码在android模拟器中显示一个视频文件,当视频文件存储在SD卡中时它工作正常。但是当我给视频的任何URL代码不起作用时。
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.View;
import android.widget.*;
public class playerActivity extends Activity
{
Button b;
VideoView preview;
SurfaceHolder holder;
MediaPlayer mp;
private String path = "/data/data/payoda.android/funny.mp4";
//private String path = "http://www.daily3gp.com/vids/3.3gp";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
preview=(VideoView)findViewById(R.id.surface);
holder=preview.getHolder();
b=(Button)findViewById(R.id.cmd_play);
b.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try
{
mp=new MediaPlayer();
mp.setDataSource(path);
mp.setScreenOnWhilePlaying(true);
mp.setDisplay(holder);
mp.prepare();
mp.start();
}
catch(Exception e)
{
}
}
});
}
}这个例外是:
prepare failed:
status=0xC8LogCat详细信息如下:
09-16 12:16:36.729: ERROR/PlayerDriver(542): Command PLAYER_INIT completed with an error or info PVMFErrContentInvalidForProgressivePlayback
09-16 12:16:36.739: ERROR/MediaPlayer(2867): error (200, -27)在上面的代码中如果更改路径变量,模拟器屏幕是黑色的单个按钮。可能我需要做更多的事情来显示远程URL中的视频,我不知道该怎么做。任何人都对此有任何想法请帮帮我。