package com.example.exportmedia

import android.content.Context
import com.github.hiteshsondhi88.libffmpeg.FFmpeg
import com.github.hiteshsondhi88.libffmpeg.FFmpegExecuteResponseHandler
import com.github.hiteshsondhi88.libffmpeg.FFmpegLoadBinaryResponseHandler
import com.github.hiteshsondhi88.libffmpeg.exceptions.FFmpegNotSupportedException

class MediaHelper {

    var context: Context? = null

    private var ffmpeg: FFmpeg? = null

    fun init(context: Context) {
        this.context = context
        ffmpeg = FFmpeg.getInstance(context)
        try {
            ffmpeg?.loadBinary(object : FFmpegLoadBinaryResponseHandler {
                override fun onSuccess() {
                }

                override fun onFailure() {
                }

                override fun onFinish() {
                }

                override fun onStart() {
                }
            })
        } catch (e: FFmpegNotSupportedException) {

        }
    }

    fun execute(cmd: Array<String>, mediaCallBack: MediaCallBack) {
        ffmpeg?.execute(cmd, object : FFmpegExecuteResponseHandler {
            override fun onFinish() {
                mediaCallBack.onExecuteFinish()
            }

            override fun onSuccess(message: String?) {
                mediaCallBack.onExecuteSuccess(message)
            }

            override fun onFailure(message: String?) {
                mediaCallBack.onExecuteFailed(message)
            }

            override fun onProgress(message: String?) {
            }

            override fun onStart() {
            }
        })
    }
}