Skip to content

Commit

Permalink
播放器新增画面适配模式:
Browse files Browse the repository at this point in the history
1、FM_WH_16X9 宽高比:16;9。
2、FM_FULL_SCREEN_WIDTH:全屏,宽铺满 高自适应。
3、FM_FULL_SCREEN_HEIGHT:全屏,高铺满 宽自适应。
  • Loading branch information
microshow committed Jul 29, 2020
1 parent 37e86bb commit d703a0e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void initData() {
//设置控制层容器 和 视频尺寸适配模式
mPlayerView.setController(new RxFFmpegPlayerControllerImpl(getActivity()), MeasureHelper.FitModel.FM_DEFAULT);

//静音模式
mPlayerView.setVolume(0);

//播放
mPlayerView.play(binding.editText.getText().toString(), true);

Expand Down
4 changes: 2 additions & 2 deletions configs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ ext {
//支持包版本
supportLibValue = "28.0.0"
//应用 versionCode
versionCodeValue = 450
versionCodeValue = 460
//应用 version 名称,更多设置里显示的
versionNameValue = "4.5.0"
versionNameValue = "4.6.0"

}
11 changes: 11 additions & 0 deletions rxffmpeg/src/main/java/io/microshow/rxffmpeg/player/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ public static int getScreenHeight(Context context) {
return displayMetrics.heightPixels;
}

/**
* 获取全屏的 高 去除顶部状态栏和底部导航栏
* @param context
* @return
*/
public static int getFullScreenHeight(Context context) {
DisplayMetrics outMetrics = new DisplayMetrics();
scanForActivity(context).getWindowManager().getDefaultDisplay().getRealMetrics(outMetrics);
return outMetrics.heightPixels;
}

/**
* 通过 context 找到 activity
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public enum FitModel {
/**
* 全屏,宽铺满 高自适应
*/
FM_FULL_SCREEN,
FM_FULL_SCREEN_WIDTH,

/**
* 全屏,高铺满 宽自适应
*/
FM_FULL_SCREEN_HEIGHT,

/**
* 宽高比:169
* 宽高比:169
*/
FM_WH_16X9

Expand Down Expand Up @@ -166,13 +166,13 @@ public void setVideoLayoutParams(TextureView textureView, FrameLayout container)

} else {//非全屏

if (mFitModel == FitModel.FM_FULL_SCREEN) {
if (mFitModel == FitModel.FM_FULL_SCREEN_WIDTH) {
//宽铺满,高度按比例
viewHeight = (int) (viewWidth / videoAspect);

} else if (mFitModel == FitModel.FM_FULL_SCREEN_HEIGHT) {
//高度铺满
viewHeight = Helper.getScreenHeight(getView().getContext());
viewHeight = Helper.getFullScreenHeight(getView().getContext());
//宽自适应
viewWidth = (int) (viewHeight * videoAspect);

Expand Down Expand Up @@ -221,7 +221,7 @@ public int[] doMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int viewWidth, viewHeight;

if (mFitModel == FitModel.FM_DEFAULT) {
if (mFitModel == FitModel.FM_DEFAULT || mFitModel == FitModel.FM_FULL_SCREEN_HEIGHT) {
viewWidth = widthMeasureSpec;
viewHeight = mMeasuredHeight;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ public void setTextureViewEnabledTouch(boolean enabled) {
}
}

/**
* 设置播放完成回调
* @param listener -
*/
public void setOnCompleteListener(IMediaPlayer.OnCompletionListener listener) {
if (mPlayer != null) {
mPlayer.setOnCompleteListener(listener);
}
}

public FrameLayout getContainerView() {
return mContainer;
}
Expand All @@ -227,6 +237,9 @@ public void setFitModel(MeasureHelper.FitModel fitModel) {
public void play(String videoPath, boolean isLooping) {
if (mPlayer != null && !Helper.isFastClick()) {
mPlayer.play(videoPath, isLooping);
if (mPlayerController != null) {
mPlayerController.onResume();
}
}
}

Expand Down
23 changes: 12 additions & 11 deletions rxffmpeg/src/main/res/layout/rxffmpeg_player_controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@
android:visibility="visible"
tools:ignore="UnusedAttribute" />

<ImageView
android:id="@+id/iv_mute"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_margin="10dp"
android:contentDescription="@null"
android:src="@mipmap/rxffmpeg_player_unmute" />

<RelativeLayout
android:id="@+id/bottomPanel"
android:layout_width="match_parent"
Expand Down Expand Up @@ -56,12 +46,23 @@
android:layout_toEndOf="@id/iv_play"
android:textColor="#ffffff" />

<ImageView
android:id="@+id/iv_mute"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_alignParentEnd="true"
android:contentDescription="@null"
android:src="@mipmap/rxffmpeg_player_unmute" />

<SeekBar
android:id="@+id/progress_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/time_view" />
android:layout_toEndOf="@id/time_view"
android:layout_toStartOf="@id/iv_mute"/>

</RelativeLayout>

Expand Down

0 comments on commit d703a0e

Please sign in to comment.