欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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文件,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧

使用VideoView播放MP4

播放示例

實(shí)現(xiàn)簡(jiǎn)單的播放功能,播放手機(jī)本地的MP4文件。不依賴任何第三方框架,不添加任何防腐劑。
添加一個(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)整到最開始的地方,開始從頭播放。

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

相關(guān)文章

  • Android UI實(shí)現(xiàn)單行文本水平觸摸滑動(dòng)效果

    Android UI實(shí)現(xiàn)單行文本水平觸摸滑動(dòng)效果

    這篇文章主要為大家詳細(xì)介紹了Android UI實(shí)現(xiàn)單行文本水平觸摸滑動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android handler 詳解(面試必問)

    Android handler 詳解(面試必問)

    這篇文章主要介紹了Android handler的相關(guān)資料,涉及到handler相關(guān)知識(shí),需要的朋友可以參考下
    2016-02-02
  • Android 雙進(jìn)程守護(hù)的實(shí)現(xiàn)代碼

    Android 雙進(jìn)程守護(hù)的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 雙進(jìn)程守護(hù)的實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2018-08-08
  • Android事件分發(fā)的事件由來(lái)原理分析

    Android事件分發(fā)的事件由來(lái)原理分析

    這篇文章主要為大家介紹了Android事件分發(fā)的事件由來(lái)原理分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Android?studio開發(fā)實(shí)現(xiàn)計(jì)算器功能

    Android?studio開發(fā)實(shí)現(xiàn)計(jì)算器功能

    這篇文章主要為大家詳細(xì)介紹了Android?studio開發(fā)實(shí)現(xiàn)計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android控件PopupWindow模仿ios底部彈窗

    Android控件PopupWindow模仿ios底部彈窗

    這篇文章主要為大家詳細(xì)介紹了Android控件PopupWindow仿ios底部彈窗效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android 如何實(shí)現(xiàn)亮度自動(dòng)調(diào)節(jié)

    Android 如何實(shí)現(xiàn)亮度自動(dòng)調(diào)節(jié)

    這篇文章主要介紹了Android 如何實(shí)現(xiàn)亮度自動(dòng)調(diào)節(jié),幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下
    2021-04-04
  • Android實(shí)用小技巧之利用Lifecycle寫出更好維護(hù)的代碼

    Android實(shí)用小技巧之利用Lifecycle寫出更好維護(hù)的代碼

    lifecycle是一個(gè)類,用于存儲(chǔ)有關(guān)組件(如Activity或Fragment)的生命周期狀態(tài)的信息,并允許其他對(duì)象觀察此狀態(tài),下面這篇文章主要給大家介紹了關(guān)于Android實(shí)用小技巧之利用Lifecycle寫出更好維護(hù)的代碼的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • 詳解如何魔改Retrofit實(shí)例

    詳解如何魔改Retrofit實(shí)例

    這篇文章主要為大家介紹了詳解如何魔改Retrofit實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • android仿微信聯(lián)系人索引列表功能

    android仿微信聯(lián)系人索引列表功能

    這篇文章主要為大家詳細(xì)介紹了android仿微信聯(lián)系人索引列表功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11

最新評(píng)論