Skip to content

Commit

Permalink
1、新增音量设置接口:setVolume(int percent); //percent 取值范围( 0 - 100 ); 0是静音;
Browse files Browse the repository at this point in the history
2、新增 setMuteSolo(int mute); //设置声道;0立体声;1左声道;2右声道
3、视屏全屏模式下按系统返回键退出全屏
  • Loading branch information
microshow committed May 11, 2020
1 parent 8edd71b commit e28a127
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,34 @@ private View getHomeTabItem(int index) {
public boolean onKeyDown(int keyCode, KeyEvent event) {

Fragment mFragment = getSupportFragmentManager().findFragmentByTag(myTabhost.getCurrentTabTag());
MeFragment mFindFragment = null;
MeFragment mMeFragment = null;
FindFragment mFindFragment = null;

if (mFragment instanceof MeFragment) {
mFindFragment = (MeFragment) mFragment;
mMeFragment = (MeFragment) mFragment;
}

if (mFindFragment != null && mFindFragment.onKeyDown(keyCode, event)) {
return true;
if (mFragment instanceof FindFragment) {
mFindFragment = (FindFragment) mFragment;
}

if (mMeFragment != null) {
if (mMeFragment.onKeyDown(keyCode, event)) {
return true;
} else {
return super.onKeyDown(keyCode, event);
}

} else if (mFindFragment != null) {
if (mFindFragment.onKeyDown(keyCode, event)) {
return true;
} else {
return super.onKeyDown(keyCode, event);
}

} else {
return super.onKeyDown(keyCode, event);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.microshow.rxffmpeg.app.fragment;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -44,6 +45,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

public abstract void initData();

public boolean onKeyDown(int keyCode, KeyEvent event) {
return false;
}

/**
* 获取当前类名(没有包名)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;

import androidx.annotation.Nullable;
Expand Down Expand Up @@ -52,10 +53,20 @@ public void initData() {
mPlayerView.setController(new RxFFmpegPlayerControllerImpl(getActivity()), MeasureHelper.FitModel.FM_DEFAULT);

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

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (mPlayerView.isFullScreenModel()) {//当前处于全屏模式,这里需要退出全屏
mPlayerView.switchScreen();//退出全屏
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}

@Override
public void onResume() {
super.onResume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void initData() {
.go("https://github.com/microshow/RxFFmpeg");
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return agentWeb != null && agentWeb.handleKeyEvent(keyCode, event);
}
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 = 400
versionCodeValue = 410
//应用 version 名称,更多设置里显示的
versionNameValue = "4.0.0"
versionNameValue = "4.1.0"

}
Binary file modified preview/app-release.apk
Binary file not shown.
Binary file modified rxffmpeg/libs/arm64-v8a/librxffmpeg-player.so
Binary file not shown.
Binary file modified rxffmpeg/libs/armeabi-v7a/librxffmpeg-invoke.so
Binary file not shown.
Binary file modified rxffmpeg/libs/armeabi-v7a/librxffmpeg-player.so
Binary file not shown.
Binary file modified rxffmpeg/libs/x86/librxffmpeg-invoke.so
Binary file not shown.
Binary file modified rxffmpeg/libs/x86/librxffmpeg-player.so
Binary file not shown.
Binary file modified rxffmpeg/libs/x86_64/librxffmpeg-player.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,29 @@ public interface IMediaPlayer {
*/
boolean isPlaying();

/**
* 设置音量
* @param percent 取值范围( 0 - 100 ); 0是静音
*/
void setVolume(int percent);

/**
* 获取音量 默认100
*/
int getVolume();

/**
* 设置声道;0立体声;1左声道;2右声道
*/
void setMuteSolo(int mute);

/**
* 获取声道:0立体声;1左声道;2右声道;
* 如果没有调用setMuteSolo,则返回-1 (默认没有设置)
* @return
*/
int getMuteSolo();

/**
* 回收流媒体资源
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ public abstract class RxFFmpegPlayer implements IMediaPlayer {

private native boolean nativeIsPlaying();

private native void nativeSetVolume(int percent);

/**
* 视频路径
*/
private String path;
private native int nativeGetVolume();

private native void nativeSetMuteSolo(int mute);

private native int nativeGetMuteSolo();

private OnPreparedListener mOnPreparedListener;

Expand All @@ -60,15 +62,20 @@ public abstract class RxFFmpegPlayer implements IMediaPlayer {

private OnCompletionListener mOnCompletionListener;

/**
* 视频路径
*/
protected String path;

/**
* 总时长
*/
private int mDuration = 0;
protected int mDuration = 0;

/**
* 循环标志
*/
private boolean looping;
protected boolean looping;

private CompositeDisposable mCompositeDisposable;

Expand Down Expand Up @@ -148,6 +155,26 @@ public boolean isPlaying() {
return nativeIsPlaying();
}

@Override
public void setVolume(int percent) {
nativeSetVolume(percent);
}

@Override
public int getVolume() {
return nativeGetVolume();
}

@Override
public void setMuteSolo(int mute) {
nativeSetMuteSolo(mute);
}

@Override
public int getMuteSolo() {
return nativeGetMuteSolo();
}

@Override
public void release() {
setOnPreparedListener(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RxFFmpegPlayerControllerImpl extends RxFFmpegPlayerController {
private View mBottomPanel;
private ImageView playBtn;
private View repeatPlay;
private ImageView muteImage;//静音图标

private boolean isSeeking = false;
public int mPosition;
Expand Down Expand Up @@ -64,6 +65,14 @@ public void onClick(View view) {
}
}
});
muteImage = findViewById(R.id.iv_mute);
muteImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
//静音
switchMute();
}
});

playBtn.setOnClickListener(new OnClickListener() {
@Override
Expand All @@ -79,6 +88,20 @@ public void onClick(View view) {
});
}

public void switchMute() {
if (mPlayerView != null) {
if (mPlayerView.getVolume() == 0) {
//当前是静音,设置为非静音
mPlayerView.setVolume(100);
muteImage.setImageResource(R.mipmap.rxffmpeg_player_unmute);
} else {
//当前不是静音,设置为静音
mPlayerView.setVolume(0);
muteImage.setImageResource(R.mipmap.rxffmpeg_player_mute);
}
}
}

@Override
public void initListener() {
PlayerListener mPlayerListener = new PlayerListener(this);
Expand Down Expand Up @@ -231,6 +254,10 @@ public void onPause() {
public void onResume() {
playBtn.setImageResource(R.mipmap.rxffmpeg_player_pause);
playBtn.animate().alpha(1f).start();//隐藏 播放按钮
//设置静音图标
if (mPlayerView != null) {
muteImage.setImageResource(mPlayerView.getVolume() == 0 ? R.mipmap.rxffmpeg_player_mute : R.mipmap.rxffmpeg_player_unmute);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,48 @@ public boolean isLooping() {
// mPlayer.stop();
// }

/**
* 设置音量 (需要在play方法之前调用)
* @param percent 取值范围( 0 - 100 ); 0是静音
*/
public void setVolume(int percent) {
if (mPlayer != null) {
mPlayer.setVolume(percent);
}
}

/**
* 获取音量
* @return volume
*/
public int getVolume() {
if (mPlayer != null) {
return mPlayer.getVolume() != -1 ? mPlayer.getVolume() : 100;
} else {
return 100;
}
}

/**
* 设置声道;0立体声;1左声道;2右声道
*/
public void setMuteSolo(int mute) {
if (mPlayer != null) {
mPlayer.setMuteSolo(mute);
}
}

/**
* 获取声道:0立体声;1左声道;2右声道;
*/
public int getMuteSolo() {
if (mPlayer != null) {
return mPlayer.getMuteSolo() != -1 ? mPlayer.getMuteSolo() : 0;
} else {
return 0;
}
}

/**
* 销毁
*/
Expand All @@ -243,27 +285,36 @@ public void release() {
setKeepScreenOn(false);//设置屏幕保持常亮
}

/**
* 当前是否是全屏
* @return true:是;false:否
*/
public boolean isFullScreenModel() {
return mCurrentMode == MODE_FULL_SCREEN;
}

/**
* 切换全屏或关闭全屏
* @return true已经进入到全屏
*/
public void switchScreen() {
if (mCurrentMode == MODE_FULL_SCREEN) {
public boolean switchScreen() {
if (isFullScreenModel()) {
//是全屏 则退出全屏
exitFullScreen();//退出全屏
return exitFullScreen();//退出全屏
} else {
enterFullScreen();//进入全屏
return enterFullScreen();//进入全屏
}
}

/**
* 进入全屏
*/
public void enterFullScreen() {
if (mCurrentMode == MODE_FULL_SCREEN) return;
public boolean enterFullScreen() {
if (mCurrentMode == MODE_FULL_SCREEN) return false;

ViewGroup decorView = Helper.setFullScreen(mContext, true);
if (decorView == null)
return;
return false;

this.removeView(mContainer);

Expand All @@ -273,17 +324,19 @@ public void enterFullScreen() {
decorView.addView(mContainer, params);

mCurrentMode = MODE_FULL_SCREEN;

return true;
}

/**
* 退出全屏
*/
public void exitFullScreen() {
public boolean exitFullScreen() {
if (mCurrentMode == MODE_FULL_SCREEN) {

ViewGroup decorView = Helper.setFullScreen(mContext, false);
if (decorView == null)
return;
return false;

decorView.removeView(mContainer);
LayoutParams params = new LayoutParams(
Expand All @@ -293,6 +346,7 @@ public void exitFullScreen() {

mCurrentMode = MODE_NORMAL;
}
return false;
}

//屏幕旋转后改变
Expand Down
Loading

0 comments on commit e28a127

Please sign in to comment.