【Android-視頻播放】實用vitamio自訂控制條位置

來源:互聯網
上載者:User

標籤:android   blog   color   io   ar   使用   java   sp   檔案   

在開發中,用到了視頻播放的功能,看到網上現成的開源的Vitamio已經很成熟了。就本著拿來主義直接實用了。

但是播放中實用的進度條的位置有時候跟自己需求不是那麼一致。

下面是教程

1.首先修改Vitamio中MediaController類,在此類中新加一個建構函式,代碼如下:

public MediaController(Context context,boolean fromXml,View container) {super(context);initController(context);mFromXml = fromXml;mRoot = makeControllerView();
         //這個地方的FrameLayout.LayoutpParams是因為布局檔案中要把MediaController的視圖作為childView加到一個FrameLayout中去FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);//想怎樣布局MediaController就盡情的發揮這個LayoutParams吧p.gravity = Gravity.BOTTOM;mRoot.setLayoutParams(p);((FrameLayout)container).addView(mRoot);}

  此方法中用到的所有欄位都是本來就有的,沒有新加任何代碼

2.定義播放視頻的XML布局檔案,代碼如下:

<FrameLayout        android:id="@+id/ll"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:visibility="gone" >        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:background="@color/black"            android:orientation="vertical" >            <io.vov.vitamio.widget.CenterLayout                android:id="@+id/cl"                android:layout_width="fill_parent"                android:layout_height="wrap_content"                android:background="@color/black" >                <io.vov.vitamio.widget.VideoView                    android:id="@+id/vv"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerHorizontal="true"                    android:layout_centerVertical="true" />            </io.vov.vitamio.widget.CenterLayout>        </LinearLayout>    </FrameLayout>

  3.Activity中使用

/**
*第一個參數:當前上下文
*第二個參數:一定要為TRUE,就是為了在MediaController中執行某些代碼
*第三個參數:把控制器添加到哪個View中去
*/

MediaController mc = new MediaController(this,true,llVideo);vv.setMediaController(mc);mc.setVisibility(View.GONE);//此操作是為瞭解決開啟視頻的時候控制條不走動,需要點擊下視頻才走動的問題。這樣預設情況下使用者看不到進度條,當點擊視頻的時候就可以看到正在走動的進度條了。

希望可以幫到一些人  

【玩】

 

【Android-視頻播放】實用vitamio自訂控制條位置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.