其他分享
首页 > 其他分享> > VideoView播放视频代码详解:

VideoView播放视频代码详解:

作者:互联网

VideoView播放视频代码详解,直接使用即可。

package com.video;

import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainVideoActivity extends Activity {
private VideoView video;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = getWindow();
window.addFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_vedio);
// video = (VideoView) findViewById(R.id.videoview);
// video.setVideoURI(Uri.parse("android.resource://" + R.raw.local_video));
// video.setVideoURI(Uri.parse("android.resource://com.telecom.activities/" + R.raw.local_video));
//video.setVideoURI(Uri.parse("android.resource://" + packageName + "/" + R.raw.local_video));
initView();
}

private void initView() {
video = (VideoView) findViewById(R.id.videoview);
String uri = "android.resource://" + getPackageName() + "/" + R.raw.local_video;
video.setVideoURI(Uri.parse(uri));
video.requestFocus();
video.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.setLooping(true);//设置视频重复播放
}
});
video.start();//播放视频
MediaController medis = new MediaController(MainVideoActivity.this);//显示控制条
video.setMediaController(medis);
medis.setMediaPlayer(video);//设置控制的对象
medis.show();

}
}

标签:setVideoURI,播放,Uri,详解,video,import,android,VideoView
来源: https://www.cnblogs.com/yangsunny/p/14237797.html