如何在Android中播放视频文件? [英] How to play a video file in android?
问题描述
我将视频MP4放置到我的域空间中.我有它的公共URL,现在我想在我的android应用程序中播放它;但不知道该怎么办.我使用下面的代码不起作用.跟踪控制器正在移动,但我在屏幕上看不到任何视频.
I am placed video MP4 to my domain space. I have its public URL, Now i want to play it in my android app; but don't know how can I do this. I used following code which is not working. Track controller is moving but I can't see any video on screen.
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);
}
}
推荐答案
大多数时候,我在使用以下代码:
Most of the time, I'm using following code:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
有关更多信息,请参见以下页面: http://developer.android. com/guide/topics/media/index.html 和 http://developer.android .com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.html
for more information look at this page: http://developer.android.com/guide/topics/media/index.html and http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.html
这篇关于如何在Android中播放视频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!