translate the note FilterActivity into English

translate the note FilterActivity into English
pull/166/head
xufulong 5 years ago
parent ef988b0d86
commit 3d25e20a94
  1. 19
      app/src/main/AndroidManifest.xml
  2. 19
      app/src/main/java/com/frank/ffmpeg/FFmpegApplication.java
  3. 68
      app/src/main/java/com/frank/ffmpeg/activity/FilterActivity.java
  4. 4
      app/src/main/res/layout/activity_filter.xml
  5. 14
      app/src/main/res/values/strings.xml

@ -13,6 +13,7 @@
<uses-feature android:name="android.hardware.camera.autofocus" /> <uses-feature android:name="android.hardware.camera.autofocus" />
<application <application
android:name=".FFmpegApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
@ -27,31 +28,31 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- 音频处理 --> <!-- audio handle -->
<activity android:name=".activity.AudioHandleActivity" /> <activity android:name=".activity.AudioHandleActivity" />
<!-- 音视频处理 --> <!-- media handle -->
<activity android:name=".activity.MediaHandleActivity" /> <activity android:name=".activity.MediaHandleActivity" />
<!-- 视频处理 --> <!-- video handle -->
<activity android:name=".activity.VideoHandleActivity" /> <activity android:name=".activity.VideoHandleActivity" />
<!-- 音视频解码播放 --> <!-- media player -->
<activity <activity
android:name=".activity.MediaPlayerActivity" android:name=".activity.MediaPlayerActivity"
android:screenOrientation="landscape" /> android:screenOrientation="landscape" />
<!-- 本地推流直播 --> <!-- local pusher -->
<activity <activity
android:name=".activity.PushActivity" /> android:name=".activity.PushActivity" />
<!-- 实时推流直播 --> <!-- real time pusher -->
<activity <activity
android:name=".activity.LiveActivity" android:name=".activity.LiveActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<!-- 滤镜特效 --> <!-- filter effect -->
<activity <activity
android:name=".activity.FilterActivity" android:name=".activity.FilterActivity"
android:screenOrientation="landscape" /> android:screenOrientation="landscape" />
<!--视频播放拖动预览--> <!-- video preview -->
<activity android:name=".activity.VideoPreviewActivity" <activity android:name=".activity.VideoPreviewActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<!--检测多媒体格式数据--> <!-- probe media format -->
<activity android:name=".activity.ProbeFormatActivity" <activity android:name=".activity.ProbeFormatActivity"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
</application> </application>

@ -0,0 +1,19 @@
package com.frank.ffmpeg;
import android.app.Application;
public class FFmpegApplication extends Application {
private static FFmpegApplication context;
@Override
public void onCreate() {
super.onCreate();
context = this;
}
public static FFmpegApplication getInstance() {
return context;
}
}

@ -4,8 +4,10 @@ import android.annotation.SuppressLint;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Bundle; import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
@ -13,6 +15,7 @@ import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import com.frank.ffmpeg.FFmpegApplication;
import com.frank.ffmpeg.R; import com.frank.ffmpeg.R;
import com.frank.ffmpeg.VideoPlayer; import com.frank.ffmpeg.VideoPlayer;
import com.frank.ffmpeg.adapter.HorizontalAdapter; import com.frank.ffmpeg.adapter.HorizontalAdapter;
@ -24,23 +27,21 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
* 使用ffmpeg进行滤镜 * Using ffmpeg to filter
* Created by frank on 2018/6/5. * Created by frank on 2018/6/5.
*/ */
public class FilterActivity extends BaseActivity implements SurfaceHolder.Callback{ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callback {
//本地视频路径
private String videoPath = ""; private String videoPath = "";
private VideoPlayer videoPlayer; private VideoPlayer videoPlayer;
private SurfaceView surfaceView; private SurfaceView surfaceView;
private SurfaceHolder surfaceHolder; private SurfaceHolder surfaceHolder;
//surface是否已经创建
private boolean surfaceCreated; private boolean surfaceCreated;
//是否正在播放 //is playing or not
private boolean isPlaying; private boolean isPlaying;
//滤镜数组 //the array of filter
private String[] filters = new String[]{ private String[] filters = new String[]{
"lutyuv='u=128:v=128'", "lutyuv='u=128:v=128'",
"hue='h=60:s=-3'", "hue='h=60:s=-3'",
@ -52,20 +53,20 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
"vflip", "vflip",
"unsharp" "unsharp"
}; };
//vflip is up and down, hflip is left and right
private String[] txtArray = new String[]{ private String[] txtArray = new String[]{
"素描", FFmpegApplication.getInstance().getString(R.string.filter_sketch),
"鲜明",//hue FFmpegApplication.getInstance().getString(R.string.filter_distinct),
"暖蓝", FFmpegApplication.getInstance().getString(R.string.filter_warming),
"边缘", FFmpegApplication.getInstance().getString(R.string.filter_edge),
"九宫格", FFmpegApplication.getInstance().getString(R.string.filter_division),
"均衡", FFmpegApplication.getInstance().getString(R.string.filter_equalize),
"矩形", FFmpegApplication.getInstance().getString(R.string.filter_rectangle),
"翻转",//vflip上下翻转,hflip是左右翻转 FFmpegApplication.getInstance().getString(R.string.filter_flip),
"锐化" FFmpegApplication.getInstance().getString(R.string.filter_sharpening)
}; };
private HorizontalAdapter horizontalAdapter; private HorizontalAdapter horizontalAdapter;
private RecyclerView recyclerView; private RecyclerView recyclerView;
//是否播放音频
private boolean playAudio = true; private boolean playAudio = true;
private ToggleButton btnSound; private ToggleButton btnSound;
private Button btnSelect; private Button btnSelect;
@ -73,11 +74,11 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
private final static int MSG_HIDE = 222; private final static int MSG_HIDE = 222;
private final static int DELAY_TIME = 5000; private final static int DELAY_TIME = 5000;
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
private Handler mHandler = new Handler(){ private Handler mHandler = new Handler() {
@Override @Override
public void handleMessage(Message msg) { public void handleMessage(Message msg) {
super.handleMessage(msg); super.handleMessage(msg);
if (msg.what == MSG_HIDE){//无操作5s后隐藏滤镜操作栏 if (msg.what == MSG_HIDE) { //after idle 5s, hide the controller view
recyclerView.setVisibility(View.GONE); recyclerView.setVisibility(View.GONE);
btnSound.setVisibility(View.GONE); btnSound.setVisibility(View.GONE);
btnSelect.setVisibility(View.GONE); btnSelect.setVisibility(View.GONE);
@ -85,12 +86,13 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
} }
}; };
private class HideRunnable implements Runnable{ private class HideRunnable implements Runnable {
@Override @Override
public void run() { public void run() {
mHandler.obtainMessage(MSG_HIDE).sendToTarget(); mHandler.obtainMessage(MSG_HIDE).sendToTarget();
} }
} }
private HideRunnable hideRunnable; private HideRunnable hideRunnable;
@Override @Override
@ -110,7 +112,7 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
mHandler.postDelayed(hideRunnable, DELAY_TIME); mHandler.postDelayed(hideRunnable, DELAY_TIME);
} }
private void initView(){ private void initView() {
surfaceView = getView(R.id.surface_filter); surfaceView = getView(R.id.surface_filter);
surfaceHolder = surfaceView.getHolder(); surfaceHolder = surfaceView.getHolder();
surfaceHolder.addCallback(this); surfaceHolder.addCallback(this);
@ -129,14 +131,13 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
initViewsWithClick(R.id.btn_select_file); initViewsWithClick(R.id.btn_select_file);
} }
//注册监听器 private void registerLister() {
private void registerLister(){
horizontalAdapter.setOnItemClickListener(new OnItemClickListener() { horizontalAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override @Override
public void onItemClick(int position) { public void onItemClick(int position) {
if(!surfaceCreated) if (!surfaceCreated)
return; return;
if (!FileUtil.checkFileExist(videoPath)){ if (!FileUtil.checkFileExist(videoPath)) {
showSelectFile(); showSelectFile();
return; return;
} }
@ -149,8 +150,8 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
public void onClick(View v) { public void onClick(View v) {
btnSelect.setVisibility(View.VISIBLE); btnSelect.setVisibility(View.VISIBLE);
btnSound.setVisibility(View.VISIBLE); btnSound.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.VISIBLE);//按下SurfaceView,弹出滤镜操作栏 recyclerView.setVisibility(View.VISIBLE);
mHandler.postDelayed(hideRunnable, DELAY_TIME);//5s后发消息通知隐藏滤镜操作栏 mHandler.postDelayed(hideRunnable, DELAY_TIME);
} }
}); });
@ -162,12 +163,15 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
}); });
} }
/**
* switch filter
* @param position position in the array of filters
*/
private void doFilterPlay(final int position) { private void doFilterPlay(final int position) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
//切换播放 if (isPlaying) {
if(isPlaying){
videoPlayer.again(); videoPlayer.again();
} }
isPlaying = true; isPlaying = true;
@ -176,8 +180,7 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
}).start(); }).start();
} }
//设置是否静音 private void setPlayAudio() {
private void setPlayAudio(){
playAudio = !playAudio; playAudio = !playAudio;
videoPlayer.playAudio(playAudio); videoPlayer.playAudio(playAudio);
} }
@ -201,7 +204,7 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
isPlaying = false; isPlaying = false;
//暂时注释 //FIXME
// videoPlayer.release(); // videoPlayer.release();
videoPlayer = null; videoPlayer = null;
horizontalAdapter = null; horizontalAdapter = null;
@ -217,9 +220,8 @@ public class FilterActivity extends BaseActivity implements SurfaceHolder.Callba
@Override @Override
void onSelectedFile(String filePath) { void onSelectedFile(String filePath) {
videoPath = filePath; videoPath = filePath;
//选择滤镜模式
doFilterPlay(5); doFilterPlay(5);
//默认关闭声音 //sound off by default
btnSound.setChecked(true); btnSound.setChecked(true);
} }

@ -20,8 +20,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:textOff="@string/sound_close" android:textOff="@string/sound_off"
android:textOn="@string/sound_open"/> android:textOn="@string/sound_on"/>
<Button <Button
android:id="@+id/btn_select_file" android:id="@+id/btn_select_file"

@ -48,8 +48,8 @@
<string name="stop">停止</string> <string name="stop">停止</string>
<string name="mute">静音</string> <string name="mute">静音</string>
<string name="sound">声音</string> <string name="sound">声音</string>
<string name="sound_open">声音开</string> <string name="sound_on">声音开</string>
<string name="sound_close">声音关</string> <string name="sound_off">声音关</string>
<string name="video_sketch">素描</string> <string name="video_sketch">素描</string>
<string name="video_hue">hue</string> <string name="video_hue">hue</string>
@ -73,4 +73,14 @@
<string name="converting_video">正在反转视频&#8230;</string> <string name="converting_video">正在反转视频&#8230;</string>
<string name="tip_not_mp4_video">该视频不是mp4,无法进行moov前移操作</string> <string name="tip_not_mp4_video">该视频不是mp4,无法进行moov前移操作</string>
<string name="filter_sketch">素描</string>
<string name="filter_distinct">鲜明</string>
<string name="filter_warming">暖蓝</string>
<string name="filter_edge">边缘</string>
<string name="filter_division">九宫格</string>
<string name="filter_equalize">均衡</string>
<string name="filter_rectangle">矩形</string>
<string name="filter_flip">翻转</string>
<string name="filter_sharpening">锐化</string>
</resources> </resources>

Loading…
Cancel
Save