我认为问题在于连接(http)或 VideoView 的使用。
要知道是否存在连接问题,您可以尝试在手机本地播放媒体内容,即从 SD 卡播放。
问题也来自 VideoView 的使用
VideoView 类使用 SurfaceView 和 MediaPlayer 实现视频播放。MediaPlayer 具有设置 url、准备媒体管道、启动管道等的 API。但在启动管道之前;管道必须准备好,即处于预卷状态。为了通知应用程序,MediaPlayer 提供了侦听器。在这种情况下,它是 onPrepareListener。与 MediaPlayer 交互的 VideoView 也(必须?)也提供这些侦听器。
看看下面的 VideoPlayer 活动代码,它使用 VideoView 进行播放。(仅针对本地内容进行验证)此活动从意图中获取要播放的文件的绝对路径。(从列表活动传递)
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;
public class VideoPlayer extends Activity implements OnCompletionListener, OnPreparedListener {
private static VideoView vView;
private String filePath;
public static long clipDurationMS;
private View mLoadingIndicator;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
vView = (VideoView)findViewById(R.id.VideoView01);
mLoadingIndicator = findViewById(R.id.progress_indicator);
vView.setBackgroundColor(0x0000);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
filePath = (String)extras.get("URL");
vView.setVideoPath(filePath);
MediaController mc;
mc = new MediaController(this);
vView.setMediaController(mc);
vView.requestFocus();
vView.setOnCompletionListener(this);
vView.setOnPreparedListener(this);
}
public void onCompletion(MediaPlayer arg0)
{
finish();
}
public void onPrepared(MediaPlayer arg0)
{
mLoadingIndicator.setVisibility(View.GONE);
ViewGroup.LayoutParams params;
params = vView.getLayoutParams();
params.height = arg0.getVideoHeight();
params.width = arg0.getVideoWidth();
vView.setLayoutParams(params);
vView.start();
}
public void onStop(){
super.onStop();
vView.stopPlayback();
finish();
}
}
沙什