標籤: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自訂控制條位置