首页 > 学院 > 开发设计 > 正文

多媒体(视频播放器)

2019-11-08 01:08:18
字体:
来源:转载
供稿:网友

视频播放器你可以在上面的一篇博客中继续写只需要把那个sd卡的那个路径改成这样的:

mediaPlayer.setDataSource(this, Uri.parse("file://mnt/sdcard/1/sister.mp4"));

要用这个来显示视频图像的

<SurfaceView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/sv_main01" />

java代码中写:

//将媒体播放器展示到SurfaceView mediaPlayer.setDisplay(sv_main01.getHolder());

如果你只是想做一个简单的播放视频

你就可以看下我下面写的就行完全不用多么复杂的代码:

布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_play" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <VideoView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/vv_main01" /></LinearLayout>

Java代码:

//设置视频的来源 vv_main01.setVideoPath("file://mnt/sdcard/1/advideo.mp4"); //实例化媒体控制器 MediaController mediaController=new MediaController( this); //互相设置 mediaController.setMediaPlayer(vv_main01); vv_main01.setMediaController(mediaController);
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表