android之视频播放控件VideoView简单应用

http://blog.csdn.net/chenzheng_java/article/details/6258456

[java:nogutter] view plain copy
  1. package cn.com.chenzheng_java;  
  2.   
  3. import android.app.Activity;  
  4. import android.media.MediaPlayer;  
  5. import android.os.Bundle;  
  6. import android.util.Log;  
  7. import android.widget.MediaController;  
  8. import android.widget.VideoView;  
  9. import android.widget.MediaController.MediaPlayerControl;  
  10.   
  11. public class VideoActivity extends Activity {  
  12.   
  13.     @Override  
  14.     protected void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         setContentView(R.layout.video);  
  17.           
  18.         VideoView videoView = (VideoView)findViewById(R.id.videoView1);  
  19.         /*** 
  20.          * 将播放器关联上一个音频或者视频文件 
  21.          * videoView.setVideoURI(Uri uri) 
  22.          * videoView.setVideoPath(String path) 
  23.          * 以上两个方法都可以。 
  24.          */  
  25.         videoView.setVideoPath("data/yueding.mp3");  
  26.           
  27.         /** 
  28.          * w为其提供一个控制器,控制其暂停、播放……等功能 
  29.          */  
  30.         videoView.setMediaController(new MediaController(this));  
  31.           
  32.         /** 
  33.          * 视频或者音频到结尾时触发的方法 
  34.          */  
  35.         videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {  
  36.             @Override  
  37.             public void onCompletion(MediaPlayer mp) {  
  38.                 Log.i("通知""完成");  
  39.             }  
  40.         });  
  41.           
  42.         videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {  
  43.               
  44.             @Override  
  45.             public boolean onError(MediaPlayer mp, int what, int extra) {  
  46.                 Log.i("通知""播放中出现错误");  
  47.                 return false;  
  48.             }  
  49.         });  
  50.           
  51.     }  
  52. }  

video.xml

[xhtml:nogutter] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent" android:layout_height="match_parent"  
  4.     android:orientation="horizontal">  
  5.     <VideoView android:layout_height="match_parent" android:id="@+id/videoView1"  
  6.         android:layout_width="wrap_content"></VideoView>  
  7. </LinearLayout>  

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

我们从api中,可以看到:

 setVideoPath(String path)
 

setVideoURI(Uri uri)

 

 

 

 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值