国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

5步學(xué)會(huì)使用VideoView播放視頻

2019-10-21 21:48:36
字體:
供稿:網(wǎng)友

我們可以試想ImageView能顯示圖片,而VideoView就是用來顯示視頻的。

使用VideoView播放視頻的步驟如下 

【1】在界面布局中定義VideoView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"  android:layout_height="match_parent"  android:orientation="vertical"  tools:context=".MainActivity">  <VideoView    android:id="@+id/videoview"    android:layout_width="match_parent"    android:layout_height="0dp"    android:layout_weight="1"/>  <Button    android:id="@+id/button"    android:text="播放"    android:layout_width="wrap_content"    android:layout_height="wrap_content" /></LinearLayout>

【2】調(diào)用如下兩個(gè)方法加載指定視頻

setVideoPath(String Path);加載路徑下的視頻 
setVideoURL(URL url);加載url所對(duì)應(yīng)的視頻。

mVideoView.setVideoPath(Environment.getExternalStorageDirectory()+"/aa.mp4");

【3】權(quán)限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

【4】調(diào)用 

start()、stop()、pause()控制播放 

【5】實(shí)際中常常結(jié)合MediaController類,它提供一個(gè)友好的圖像控制界面控制視頻播放;

mVideoView.setMediaController(new MediaController(MainActivity.this));

完整程序代碼如下

public class MainActivity extends Activity {  private VideoView mVideoView;  private Button mButton;  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    mVideoView= (VideoView) findViewById(R.id.videoview);    mButton= (Button) findViewById(R.id.button);    mButton.setOnClickListener(new View.OnClickListener() {      @Override      public void onClick(View v) {        //得到sdcard下面aa.mp4的視頻文件        //兩種調(diào)用方式//        File videofile =new File("/mut/extSdCard/DCIM/Camera/20150915_160202.mp4");//        mVideoView.setVideoPath(videofile.getAbsolutePath());        mVideoView.setVideoPath(Environment.getExternalStorageDirectory()+"/20150915_160202.mp4");        mVideoView.setMediaController(new MediaController(MainActivity.this));        mVideoView.start();      }    });  }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 西城区| 华安县| 永平县| 南丹县| 拉孜县| 泗阳县| 顺平县| 宝鸡市| 新宾| 英山县| 内江市| 绵竹市| 贵州省| 永吉县| 遂昌县| 嘉定区| 讷河市| 开远市| 和静县| 达州市| 义乌市| 通渭县| 宜州市| 清原| 安徽省| 合山市| 宁远县| 汶川县| 湖口县| 扎兰屯市| 定日县| 达尔| 南郑县| 甘泉县| 峡江县| 阿拉善右旗| 遂宁市| 阿克陶县| 平凉市| 镶黄旗| 石首市|