parent
							
								
									db450ae573
								
							
						
					
					
						commit
						aa7a6cd17e
					
				@ -0,0 +1,107 @@ | 
				
			||||
package com.frank.ffmpeg.activity; | 
				
			||||
 | 
				
			||||
import android.annotation.SuppressLint; | 
				
			||||
import android.os.Bundle; | 
				
			||||
import android.os.Handler; | 
				
			||||
import android.os.Message; | 
				
			||||
import android.view.View; | 
				
			||||
import android.widget.ProgressBar; | 
				
			||||
import android.widget.RelativeLayout; | 
				
			||||
import android.widget.TextView; | 
				
			||||
 | 
				
			||||
import com.frank.ffmpeg.R; | 
				
			||||
import com.frank.ffmpeg.handler.FFmpegHandler; | 
				
			||||
 | 
				
			||||
import com.frank.ffmpeg.util.FFmpegUtil; | 
				
			||||
import com.frank.ffmpeg.util.FileUtil; | 
				
			||||
 | 
				
			||||
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_BEGIN; | 
				
			||||
import static com.frank.ffmpeg.handler.FFmpegHandler.MSG_FINISH; | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Using ffprobe to parse media format data | 
				
			||||
 * Created by frank on 2020/1/7. | 
				
			||||
 */ | 
				
			||||
 | 
				
			||||
public class ProbeFormatActivity extends BaseActivity { | 
				
			||||
 | 
				
			||||
    private TextView txtProbeFormat; | 
				
			||||
    private ProgressBar progressProbe; | 
				
			||||
    private RelativeLayout layoutProbe; | 
				
			||||
    private FFmpegHandler ffmpegHandler; | 
				
			||||
 | 
				
			||||
    @SuppressLint("HandlerLeak") | 
				
			||||
    private Handler mHandler = new Handler() { | 
				
			||||
        @Override | 
				
			||||
        public void handleMessage(Message msg) { | 
				
			||||
            super.handleMessage(msg); | 
				
			||||
            switch (msg.what) { | 
				
			||||
                case MSG_BEGIN: | 
				
			||||
                    progressProbe.setVisibility(View.VISIBLE); | 
				
			||||
                    layoutProbe.setVisibility(View.GONE); | 
				
			||||
                    break; | 
				
			||||
                case MSG_FINISH: | 
				
			||||
                    progressProbe.setVisibility(View.GONE); | 
				
			||||
                    layoutProbe.setVisibility(View.VISIBLE); | 
				
			||||
                    break; | 
				
			||||
                default: | 
				
			||||
                    break; | 
				
			||||
            } | 
				
			||||
        } | 
				
			||||
    }; | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    int getLayoutId() { | 
				
			||||
        return R.layout.activity_probe; | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    protected void onCreate(Bundle savedInstanceState) { | 
				
			||||
        super.onCreate(savedInstanceState); | 
				
			||||
 | 
				
			||||
        hideActionBar(); | 
				
			||||
        initView(); | 
				
			||||
        ffmpegHandler = new FFmpegHandler(mHandler); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    private void initView() { | 
				
			||||
        progressProbe = getView(R.id.progress_probe); | 
				
			||||
        layoutProbe = getView(R.id.layout_probe); | 
				
			||||
        initViewsWithClick(R.id.btn_probe_format); | 
				
			||||
        txtProbeFormat = getView(R.id.txt_probe_format); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    public void onViewClick(View view) { | 
				
			||||
        selectFile(); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    void onSelectedFile(String filePath) { | 
				
			||||
        doHandleAudio(filePath); | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    /** | 
				
			||||
     * use ffprobe to parse video/audio format metadata | 
				
			||||
     * | 
				
			||||
     * @param srcFile srcFile | 
				
			||||
     */ | 
				
			||||
    private void doHandleAudio(final String srcFile) { | 
				
			||||
        if (!FileUtil.checkFileExist(srcFile)) { | 
				
			||||
            return; | 
				
			||||
        } | 
				
			||||
        String[] commandLine = FFmpegUtil.probeFormat(srcFile); | 
				
			||||
        if (ffmpegHandler != null) { | 
				
			||||
            ffmpegHandler.executeFFprobeCmd(commandLine); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
    @Override | 
				
			||||
    protected void onDestroy() { | 
				
			||||
        super.onDestroy(); | 
				
			||||
        if (mHandler != null) { | 
				
			||||
            mHandler.removeCallbacksAndMessages(null); | 
				
			||||
        } | 
				
			||||
    } | 
				
			||||
 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,35 @@ | 
				
			||||
<?xml version="1.0" encoding="utf-8"?> | 
				
			||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | 
				
			||||
    android:layout_width="match_parent" | 
				
			||||
    android:layout_height="match_parent"> | 
				
			||||
 | 
				
			||||
    <RelativeLayout | 
				
			||||
        android:id="@+id/layout_probe" | 
				
			||||
        android:layout_width="match_parent" | 
				
			||||
        android:layout_height="match_parent"> | 
				
			||||
        <Button | 
				
			||||
            android:id="@+id/btn_probe_format" | 
				
			||||
            android:layout_width="wrap_content" | 
				
			||||
            android:layout_height="wrap_content" | 
				
			||||
            android:layout_marginTop="60dp" | 
				
			||||
            android:text="@string/media_probe" | 
				
			||||
            android:textColor="@color/colorPrimary" | 
				
			||||
            android:layout_centerHorizontal="true"/> | 
				
			||||
 | 
				
			||||
        <TextView | 
				
			||||
            android:id="@+id/txt_probe_format" | 
				
			||||
            android:layout_width="wrap_content" | 
				
			||||
            android:layout_height="wrap_content" | 
				
			||||
            android:layout_marginTop="20dp" | 
				
			||||
            android:layout_below="@+id/btn_probe_format" | 
				
			||||
            android:layout_centerHorizontal="true"/> | 
				
			||||
    </RelativeLayout> | 
				
			||||
 | 
				
			||||
    <ProgressBar | 
				
			||||
        android:id="@+id/progress_probe" | 
				
			||||
        android:layout_width="wrap_content" | 
				
			||||
        android:layout_height="wrap_content" | 
				
			||||
        android:layout_centerInParent="true" | 
				
			||||
        android:visibility="gone"/> | 
				
			||||
 | 
				
			||||
</RelativeLayout> | 
				
			||||
					Loading…
					
					
				
		Reference in new issue