增加设置静音开关、5s无操作后隐藏操作栏

增加设置静音开关、5s无操作后隐藏操作栏
pull/107/head
frank 6 years ago
parent 28689818cd
commit afb5daa361
  1. 7
      app/src/main/cpp/video_filter.c
  2. 11
      app/src/main/java/com/frank/ffmpeg/VideoPlayer.java
  3. 64
      app/src/main/java/com/frank/ffmpeg/activity/FilterActivity.java
  4. 9
      app/src/main/res/layout/activity_filter.xml
  5. 2
      app/src/main/res/values/strings.xml

@ -62,6 +62,7 @@ enum AVSampleFormat out_sample_fmt;
int audio_stream_index = -1;
int got_frame;
AVCodecContext *audioCodecCtx;
jboolean playAudio = JNI_TRUE;
//const char *filter_descr = "lutyuv='u=128:v=128'";//黑白
//const char *filter_descr = "hue='h=60:s=-3'";//hue滤镜
@ -328,7 +329,7 @@ int play_audio(JNIEnv * env, AVPacket* packet, AVFrame* frame){
}
JNIEXPORT jint JNICALL Java_com_frank_ffmpeg_VideoPlayer_filter
(JNIEnv * env, jclass clazz, jstring filePath, jobject surface, jstring filterDescr, jboolean playAudio){
(JNIEnv * env, jclass clazz, jstring filePath, jobject surface, jstring filterDescr){
int ret;
const char * file_name = (*env)->GetStringUTFChars(env, filePath, JNI_FALSE);
@ -452,4 +453,8 @@ JNIEXPORT void JNICALL Java_com_frank_ffmpeg_VideoPlayer_again(JNIEnv * env, jcl
JNIEXPORT void JNICALL Java_com_frank_ffmpeg_VideoPlayer_release(JNIEnv * env, jclass clazz) {
release = 1;
}
JNIEXPORT void JNICALL Java_com_frank_ffmpeg_VideoPlayer_playAudio(JNIEnv * env, jclass clazz, jboolean play_audio) {
playAudio = play_audio;
}

@ -17,10 +17,17 @@ public class VideoPlayer {
public native int play(String filePath, Object surface);
public native int setPlayRate(float playRate);
public native int filter(String filePath, Object surface, String filterType, boolean playAudio);
public native int filter(String filePath, Object surface, String filterType);
public native void again();
public native void release();
public native void playAudio(boolean play);
/**
* 创建AudioTrack对象供JNI调用
* @param sampleRate sampleRate
* @param channels channels
* @return AudioTrack
*/
public AudioTrack createAudioTrack(int sampleRate, int channels){
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int channelConfig;

@ -1,12 +1,19 @@
package com.frank.ffmpeg.activity;
import android.annotation.SuppressLint;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
import com.frank.ffmpeg.R;
import com.frank.ffmpeg.VideoPlayer;
import com.frank.ffmpeg.adapter.HorizontalAdapter;
@ -24,6 +31,7 @@ public class FilterActivity extends AppCompatActivity implements SurfaceHolder.C
private final static String VIDEO_PATH = PATH + File.separator + "Beyond.mp4";
private VideoPlayer videoPlayer;
private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder;
//surface是否已经创建
private boolean surfaceCreated;
@ -55,8 +63,32 @@ public class FilterActivity extends AppCompatActivity implements SurfaceHolder.C
"锐化"
};
private HorizontalAdapter horizontalAdapter;
private RecyclerView recyclerView;
//是否播放音频
private boolean playAudio = true;
private ToggleButton btnSound;
private final static int MSG_HIDE = 222;
private final static int DELAY_TIME = 5000;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what == MSG_HIDE){//无操作5s后隐藏滤镜操作栏
recyclerView.setVisibility(View.GONE);
btnSound.setVisibility(View.GONE);
}
}
};
private class HideRunnable implements Runnable{
@Override
public void run() {
mHandler.obtainMessage(MSG_HIDE).sendToTarget();
}
}
private HideRunnable hideRunnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -66,15 +98,19 @@ public class FilterActivity extends AppCompatActivity implements SurfaceHolder.C
initView();
registerLister();
hideRunnable = new HideRunnable();
mHandler.postDelayed(hideRunnable, DELAY_TIME);
}
private void initView(){
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_filter);
surfaceView = (SurfaceView) findViewById(R.id.surface_filter);
surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this);
videoPlayer = new VideoPlayer();
btnSound = (ToggleButton) findViewById(R.id.btn_sound);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(linearLayoutManager);
@ -100,11 +136,33 @@ public class FilterActivity extends AppCompatActivity implements SurfaceHolder.C
videoPlayer.again();
}
isPlaying = true;
videoPlayer.filter(VIDEO_PATH, surfaceHolder.getSurface(), filters[mPosition], playAudio);
videoPlayer.filter(VIDEO_PATH, surfaceHolder.getSurface(), filters[mPosition]);
}
}).start();
}
});
surfaceView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnSound.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.VISIBLE);//按下SurfaceView,弹出滤镜操作栏
mHandler.postDelayed(hideRunnable, DELAY_TIME);//5s后发消息通知隐藏滤镜操作栏
}
});
btnSound.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
setPlayAudio();
}
});
}
//设置是否静音
private void setPlayAudio(){
playAudio = !playAudio;
videoPlayer.playAudio(playAudio);
}
@Override

@ -14,4 +14,13 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ToggleButton
android:id="@+id/btn_sound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textOff="@string/sound_close"
android:textOn="@string/sound_open"/>
</RelativeLayout>

@ -41,6 +41,8 @@
<string name="stop">停止</string>
<string name="mute">静音</string>
<string name="sound">声音</string>
<string name="sound_open">声音开</string>
<string name="sound_close">声音关</string>
<string name="video_sketch">素描</string>
<string name="video_hue">hue</string>

Loading…
Cancel
Save