我将视频 MP4 放到了我的域空间中。我有它的公共(public) URL,现在我想在我的 android 应用程序中播放它;但不知道我该怎么做。我使用了以下不起作用的代码。轨道 Controller 正在移动,但我在屏幕上看不到任何视频。
public class MPlayer extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.playvideo);
VideoView videoView = new VideoView(MPlayer.this);
videoView.setMediaController(new MediaController(this));
videoView.setVideoURI(Uri.parse("http://www.semanticdevlab.com/abc.mp4"));
videoView.requestFocus();
videoView.start();
LinearLayout l = (LinearLayout)findViewById(R.id.mplayer);
l.addView(videoView);
}
}
最佳答案
VideoView 类可以从各种来源(例如资源或内容提供者)加载图像,负责从视频计算其尺寸,以便它可以在任何布局管理器中使用,并提供各种显示选项,例如缩放和着色。
代码:
videoView = (VideoView)findViewById(R.id.ViewVideo);
videoView.setVideoURI(Uri.parse(“android.resource://” + getPackageName() +”/”+R.raw.video));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus();
videoView.start();
如果你想查看源代码: Play video file using VideoView in Android
关于android - 如何在android中播放视频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6040226/