parent
7c4b591ef3
commit
3e8442ce4a
@ -1,125 +0,0 @@ |
||||
package com.frank.ffmpeg.activity; |
||||
|
||||
import android.os.Bundle; |
||||
import android.text.TextUtils; |
||||
import android.util.Log; |
||||
import android.view.SurfaceHolder; |
||||
import android.view.SurfaceView; |
||||
import android.view.View; |
||||
|
||||
import com.frank.ffmpeg.R; |
||||
import com.frank.ffmpeg.VideoPlayer; |
||||
import com.frank.ffmpeg.util.FileUtil; |
||||
|
||||
/** |
||||
* 使用ffmpeg播放视频 |
||||
* Created by frank on 2018/2/1. |
||||
*/ |
||||
public class VideoPlayerActivity extends BaseActivity implements SurfaceHolder.Callback { |
||||
private static final String TAG = VideoPlayerActivity.class.getSimpleName(); |
||||
SurfaceHolder surfaceHolder; |
||||
private VideoPlayer videoPlayer; |
||||
//播放倍率
|
||||
private float playRate = 1; |
||||
|
||||
private boolean surfaceCreated; |
||||
|
||||
private String videoPath; |
||||
|
||||
@Override |
||||
int getLayoutId() { |
||||
return R.layout.activity_video_player; |
||||
} |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
|
||||
videoPath = getIntent().getStringExtra("videoHandlePath"); |
||||
initView(); |
||||
initPlayer(); |
||||
showToast(getString(R.string.please_click_select)); |
||||
} |
||||
|
||||
private void initView() { |
||||
SurfaceView surfaceView = getView(R.id.surface_view); |
||||
surfaceHolder = surfaceView.getHolder(); |
||||
surfaceHolder.addCallback(this); |
||||
|
||||
initViewsWithClick(R.id.btn_slow); |
||||
initViewsWithClick(R.id.btn_fast); |
||||
} |
||||
|
||||
private void initPlayer(){ |
||||
videoPlayer = new VideoPlayer(); |
||||
} |
||||
|
||||
@Override |
||||
public void surfaceCreated(SurfaceHolder holder) { |
||||
surfaceCreated = true; |
||||
if (!TextUtils.isEmpty(videoPath)) { |
||||
startPlay(videoPath); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void surfaceDestroyed(SurfaceHolder holder) { |
||||
|
||||
} |
||||
|
||||
private void startPlay(final String filePath) { |
||||
new Thread(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
if (!FileUtil.checkFileExist(filePath)) { |
||||
return; |
||||
} |
||||
|
||||
videoPlayer.play(filePath, surfaceHolder.getSurface()); |
||||
} |
||||
}).start(); |
||||
} |
||||
|
||||
@Override |
||||
protected void onDestroy() { |
||||
super.onDestroy(); |
||||
if(videoPlayer != null){ |
||||
videoPlayer = null; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
void onViewClick(View view) { |
||||
switch (view.getId()) { |
||||
case R.id.btn_fast: |
||||
if(playRate >= 1/32){ |
||||
playRate *= 0.5; |
||||
} |
||||
Log.i(TAG, "fast playRate=" + playRate); |
||||
videoPlayer.setPlayRate(playRate); |
||||
break; |
||||
case R.id.btn_slow: |
||||
if(playRate <= 32){ |
||||
playRate *= 2; |
||||
} |
||||
Log.i(TAG, "slow playRate=" + playRate); |
||||
videoPlayer.setPlayRate(playRate); |
||||
break; |
||||
default: |
||||
break; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
void onSelectedFile(String filePath) { |
||||
if (surfaceCreated) { |
||||
startPlay(filePath); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,31 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context="com.frank.ffmpeg.activity.VideoPlayerActivity"> |
||||
|
||||
<SurfaceView |
||||
android:id="@+id/surface_view" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" /> |
||||
|
||||
<Button |
||||
android:id="@+id/btn_slow" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentBottom="true" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_margin="16dp" |
||||
android:text="@string/video_slow"/> |
||||
|
||||
<Button |
||||
android:id="@+id/btn_fast" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentBottom="true" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_margin="16dp" |
||||
android:text="@string/video_fast"/> |
||||
|
||||
</RelativeLayout> |
Loading…
Reference in new issue