本文实例为大家分享了使用VideoView播放App中资源文件的具体代码,供大家参考,具体内容如下

布局文件

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/vv_video"

android:layout_width="match_parent"

android:layout_height="match_parent" />

先在res下新建一个文件夹raw,然后将视频复制到该文件夹下面。

具体实现代码

public class VideoActivity extends Activity{

VideoView videoView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_video);

initView();

}

public void initView(){

videoView= (VideoView) findViewById(R.id.vv_video);

playVideo();

}

public void playVideo(){

//String file=Environment.getExternalStorageDirectory().getPath()+"/oppo.3gp";//oppo.3gp视频播放的名字

String uri = "android.resource://" + getPackageName() + "/" + R.raw.oppo;

videoView.setVideoURI(Uri.parse(uri));

MediaController mc = new MediaController(this);

//设置控制器 控制的是那一个videoview

mc.setAnchorView(videoView);

//设置videoview的控制器为mc

videoView.setMediaController(mc);

videoView.start();

}

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐