最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 使用VideoView播放MP4的簡(jiǎn)單實(shí)現(xiàn)

 更新時(shí)間:2018年05月28日 09:22:35   作者:RustFisher  
這篇文章主要介紹了Android 使用VideoView播放MP4的簡(jiǎn)單實(shí)現(xiàn),實(shí)現(xiàn)簡(jiǎn)單的播放功能,播放手機(jī)本地的MP4文件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

使用VideoView播放MP4

播放示例

實(shí)現(xiàn)簡(jiǎn)單的播放功能,播放手機(jī)本地的MP4文件。不依賴(lài)任何第三方框架,不添加任何防腐劑。
添加一個(gè)系統(tǒng)自帶的控制條。

相關(guān)代碼請(qǐng)參閱: https://github.com/RustFisher/android-MediaPlayer/tree/master/appMp4

申請(qǐng)權(quán)限

讀取存儲(chǔ)中的MP4文件

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

準(zhǔn)備布局文件

frag_video_view.xml中放置VideoView;為了讓內(nèi)容居中顯示,將其套在LinearLayout中,并選擇android:layout_gravity="center"。否則可能會(huì)出現(xiàn)視頻內(nèi)容不居中的情況。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@android:color/black">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <VideoView
      android:id="@+id/video_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center" />

  </LinearLayout>

  <TextView
    android:id="@+id/path_tv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/white"
    android:textSize="13sp" />

</RelativeLayout>

在Fragment中直接播放視頻文件;

  private static String mMP4Path;
  VideoView mVideoView;
  MediaController mMediaController;

  @Override
  public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    TextView pathTv = view.findViewById(R.id.path_tv);
    mVideoView = view.findViewById(R.id.video_view);
    mMediaController = new MediaController(getContext());
    if (!TextUtils.isEmpty(mMP4Path)) {
      mVideoView.setVideoPath(mMP4Path);
      mVideoView.setMediaController(mMediaController);
      mVideoView.seekTo(0);
      mVideoView.requestFocus();
      mVideoView.start();
      pathTv.setText(mMP4Path);
    }
  }

Fragment視圖創(chuàng)建完畢時(shí),設(shè)置MP4文件路徑,添加控制器,調(diào)整到最開(kāi)始的地方,開(kāi)始從頭播放。

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

相關(guān)文章

最新評(píng)論

大竹县| 晋江市| 安丘市| 靖江市| 五原县| 施秉县| 辽阳县| 黄石市| 鸡泽县| 辽源市| 西平县| 尼木县| 镇安县| 安塞县| 仁布县| 黄大仙区| 屯昌县| 拉萨市| 隆尧县| 英吉沙县| 武清区| 沧州市| 科技| 金阳县| 获嘉县| 安吉县| 二手房| 富顺县| 闵行区| 安康市| 阜阳市| 巴林左旗| 兴业县| 饶河县| 万山特区| 新巴尔虎右旗| 二连浩特市| 柯坪县| 神农架林区| 柳林县| 泉州市|