多媒体(视频播放器)

来源:互联网 发布:情定三生向天和知夏 编辑:程序博客网 时间:2024/05/01 03:13

视频播放器你可以在上面的一篇博客中继续写只需要把那个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);
1 0
原创粉丝点击