Android開發之JieCaoVideoPlayer功能的使用方法

在Android開發中,有些技術人員可能對於JieCaoVideoPlayer功能不知道如何使用,那麼接下來鄭州app開發公司燚軒科技就來跟大家分析一下該功能的使用方法吧。

compile 'fm.jiecao:jiecaovideoplayer:5.5'

<activity android:name=".JieCaoVideoActivity"

android:configChanges="orientation|screenSize|keyboardHidden"

android:screenOrientation="portrait"></activity>

 

 

這種方法小屏切換到大屏是創建了兩個播放器,或者說是創建了兩個TextureView的容器,從小到大的時候在Activity中創建了一個全屏的播放器容器,並把當前的視頻渲染器(TextureView)和監聽器都給賦值過去了,由於使用了TextureView,所以在滾動控件中使用也不會用果凍效果,可以說是正真意義的完美的播放器全屏方案。大小切換由於TextureView的容器換了,所以中間會有很短時間的黑屏,但是可以忽略

/**

* 小屏窗口切換爲全屏播放

*/

public void startWindowFullscreen() {

Log.i(TAG, "startWindowFullscreen " + " [" + this.hashCode() + "] ");

hideSupportActionBar(getContext());

/**activity的content layout**/

ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);

/**通過id找到播放器自己本身**/

View old = vp.findViewById(FULLSCREEN_ID);

/**如果在設置全屏之前activity的content layout中本來就存在播放器就先移除**/

if (old != null) {

vp.removeView(old);

}

if (textureViewContainer.getChildCount() > 0) {

textureViewContainer.removeAllViews();

}

try {

Constructor constructor = (Constructor) JCVideoPlayer.this.getClass().getConstructor(Context.class);

JCVideoPlayer jcVideoPlayer = constructor.newInstance(getContext());

jcVideoPlayer.setId(FULLSCREEN_ID);

/**獲取屏幕的寬高**/

WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);

int w = wm.getDefaultDisplay().getWidth();

int h = wm.getDefaultDisplay().getHeight();

FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(h, w);

lp.setMargins((w - h) / 2, -(w - h) / 2, 0, 0);

vp.addView(jcVideoPlayer, lp);

jcVideoPlayer.setUp(url, JCVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, objects);

jcVideoPlayer.setUiWitStateAndScreen(currentState);

/**小窗口和全屏的切換是創建了兩個播放器,之間的銜接全靠這個方法**/

jcVideoPlayer.addTextureView();

jcVideoPlayer.setRotation(90);

final Animation ra = AnimationUtils.loadAnimation(getContext(), R.anim.start_fullscreen);

jcVideoPlayer.setAnimation(ra);

/**監聽器的替換**/

JCVideoPlayerManager.setLastListener(this);

JCVideoPlayerManager.setListener(jcVideoPlayer);

} catch (InstantiationException e) {

e.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

}

}

參照JCVideoPlayerSimple,JCVideoPlayerStandard,JCVideoPlayerStandardWithShareButton

繼承JCVideoPlayer,JCVideoPlayer中包含所有關於播放的代碼,不包含任何UI的代碼

getLayoutId();佈局的id

Override init(Context context);這裏初始化自定義控件

Override setStateAndUi(int state);是重點,自定義各個狀態的UI,如果在其他地方修改UI應該保持謹慎

Override onTouch(),onClick();如果有需要

在自定義UI之後,應該依然按照README.md中的4步驟來調用播放器

關於控件id的問題,在Base simple ui example中的所有最基礎的id是寫死在JCVideoPlayer中的,下面的控件id已經findViewById過了不需要再findViewById

控件 id

開始按鈕 start

全屏按鈕 fullscreen

進度條 progress

總共時間 total

下方layout layout_bottom

上方layout layout_top

SurfaceView的容器 surface_container

如果想快速的集成視頻播放功能,建議參照JCVideoPlayerStandardWithShareButton來做,它繼承JCVideoPlayerStandard,JCVideoPlayerStandard的目標是和今日頭條的細節保持一致

如果想完全自定義UI,參照JCVideoPlayerStandard,如果還是存在有些疑惑的話,可以諮詢鄭州app開發公司燚軒科技。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章