package com.example.exportmedia.video

import com.example.exportmedia.MediaCallBack
import com.example.exportmedia.MediaHelper
import java.io.File

class MovieMakerV2(
        private val mediaHelper: MediaHelper,
        private val videoPath: String,
        private val audioPath: String?) {

    lateinit var mediaCallBack: MediaCallBack

    private constructor(builder: Builder) : this(
            builder.mediaHelper,
            builder.videoPath,
            builder.audioPath
    )

    fun output(file: File) {
        val arrayList = ArrayList<String>()

        arrayList.add("-i")
        arrayList.add(videoPath)
        audioPath?.let {
            arrayList.add("-i")
            arrayList.add(it)
        }
        arrayList.add("-codec")
        arrayList.add("copy")
        arrayList.add("-y")
        arrayList.add(file.path)

        mediaHelper.execute(arrayList.toTypedArray(), mediaCallBack)
    }

    class Builder(internal val mediaHelper: MediaHelper) {

        lateinit var videoPath: String

        var audioPath: String? = null

        fun build() = MovieMakerV2(this)
    }
}