4.10 Android VideoView播放视频

 

Android VideoView播放视频

标签: androidlayoutbuttonencodingclass
  18615人阅读  评论(12)  收藏  举报
  分类:
 

Android 利用自带VideoView控件播放视频


Activity

[java]  view plain  copy
 print ?
  1. public class Activity01 extends Activity  
  2. {  
  3.     /** Called when the activity is first created. */  
  4.     @Override  
  5.     public void onCreate(Bundle savedInstanceState)  
  6.     {  
  7.         super.onCreate(savedInstanceState);  
  8.   
  9.         setContentView(R.layout.main);  
  10.   
  11.   
  12.         final VideoView videoView = (VideoView) findViewById(R.id.VideoView01);  
  13.       
  14.         Button PauseButton = (Button) this.findViewById(R.id.PauseButton);  
  15.         Button LoadButton = (Button) this.findViewById(R.id.LoadButton);  
  16.         Button PlayButton = (Button) this.findViewById(R.id.PlayButton);  
  17.           
  18.         // load  
  19.         LoadButton.setOnClickListener(new OnClickListener() {  
  20.             public void onClick(View arg0)  
  21.             {  
  22. //              videoView.setVideoPath("/sdcard/test.mp4");  
  23.                 videoView.setVideoPath("android.resource://com.homer/"+R.raw.china);  
  24.                 videoView.setMediaController(new MediaController(Activity01.this));  
  25.                 videoView.requestFocus();  
  26.             }  
  27.         });  
  28.   
  29.         // play  
  30.         PlayButton.setOnClickListener(new OnClickListener() {  
  31.             public void onClick(View arg0)  
  32.             {  
  33.                 videoView.start();  
  34.             }  
  35.         });  
  36.   
  37.         // pause  
  38.         PauseButton.setOnClickListener(new OnClickListener() {  
  39.             public void onClick(View arg0)  
  40.             {  
  41.                 videoView.pause();  
  42.             }  
  43.         });  
  44.     }  
  45. }  

main.xml

[html]  view plain  copy
 print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <TextView  
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="@string/hello" />  
  11.   
  12.     <VideoView  
  13.         android:id="@+id/VideoView01"  
  14.         android:layout_width="320px"  
  15.         android:layout_height="240px" />  
  16.   
  17.     <Button  
  18.         android:id="@+id/LoadButton"  
  19.         android:layout_width="80px"  
  20.         android:layout_height="wrap_content"  
  21.         android:layout_x="30px"  
  22.         android:layout_y="300px"  
  23.         android:text="装载" />  
  24.   
  25.     <Button  
  26.         android:id="@+id/PlayButton"  
  27.         android:layout_width="80px"  
  28.         android:layout_height="wrap_content"  
  29.         android:layout_x="120px"  
  30.         android:layout_y="300px"  
  31.         android:text="播放" />  
  32.   
  33.     <Button  
  34.         android:id="@+id/PauseButton"  
  35.         android:layout_width="80px"  
  36.         android:layout_height="wrap_content"  
  37.         android:layout_x="210px"  
  38.         android:layout_y="300px"  
  39.         android:text="暂停" />  
  40.   
  41. </AbsoluteLayout>  

运行效果:



源码下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值