Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
1.6 kB
1
Indexable
Never
import android.content.res.AssetFileDescriptor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.VideoView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private static final String OUTPUT_FILE = "/path/to/your/output/merged_video.mp4";

    private VideoView videoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoView = findViewById(R.id.videoView);
        Button mergeButton = findViewById(R.id.mergeButton);
        Button playButton = findViewById(R.id.playButton);

        Uri inputFile1 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video1);
        Uri inputFile2 = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.video2);

        mergeButton.setOnClickListener(v -> {
            VideoMerger videoMerger = new VideoMerger();
            try {
                AssetFileDescriptor afd1 = getResources().openRawResourceFd(R.raw.video1);
                AssetFileDescriptor afd2 = getResources().openRawResourceFd(R.raw.video2);
                videoMerger.mergeVideos(afd1, afd2, OUTPUT_FILE);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

        playButton.setOnClickListener(v -> playMergedVideo());
    }

    private void playMergedVideo() {
        videoView.setVideoURI(Uri.parse(OUTPUT_FILE));
        videoView.start();
    }
}
Leave a Comment