package cn.com.chenzheng_java; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.util.Log; import android.widget.MediaController; import android.widget.VideoView; import android.widget.MediaController.MediaPlayerControl; public class VideoActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video); VideoView videoView = (VideoView)findViewById(R.id.videoView1); /*** * 将播放器关联上一个音频或者视频文件 * videoView.setVideoURI(Uri uri) * videoView.setVideoPath(String path) * 以上两个方法都可以。 */ videoView.setVideoPath("data/yueding.mp3"); /** * w为其提供一个控制器,控制其暂停、播放……等功能 */ videoView.setMediaController(new MediaController(this)); /** * 视频或者音频到结尾时触发的方法 */ videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Log.i("通知", "完成"); } }); videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { Log.i("通知", "播放中出现错误"); return false; } }); } }

video.xml

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

当然,我们也可以播放网络上的多媒体。

我们从api中,可以看到:

setVideoPath(String path)

setVideoURI(Uri uri)

更多相关文章

  1. android音乐播放器
  2. Android之音乐播放(二)
  3. 【notification】Android(安卓)中创建状态栏通知
  4. android 调用本地音乐播放器
  5. android 状态栏显示运行图标
  6. Android(安卓)播放音乐文件与视频文
  7. android本地音乐播放(一)
  8. Android定义一个不消失的悬停通知栏
  9. Android(安卓)BaseAdapter如何获得每一项并添加按钮事件

随机推荐

  1. android : 背景透明的 Dialog
  2. Android 判断数据库中是否存在某个表
  3. AppCompat does not support the current
  4. android 手机判断是否在充电 如断电自动
  5. Android 四大组件之再论BroadCast
  6. Android 怎样使用已存在的Database
  7. Android(安卓)顶部状态栏覆盖到应用之上?
  8. Error:(22, 0) Could not find method an
  9. Android最便捷banner轮播图实现原理及代
  10. android实现涂鸦,保存涂鸦后的图片,清屏