Skip to content Skip to sidebar Skip to footer

How To Video Record With Specific Sound Programmatically In Android?

I have created functionality to record video in my app. When I play a song, that song is recorded with video and a video file is created, similar to a dubshmash application. Now

Solution 1:

You can record video without audio and merge audio later on using mp4 parser like this:

/*
 * @param videoFile path to video file
 * @param audioFile path to audiofile
*/public String mux(String videoFile, String audioFile) {
        Movievideo=null;
        try {
            video = newMovieCreator().build(videoFile);
        } catch (RuntimeException e) {
            e.printStackTrace();
            returnnull;
        } catch (IOException e) {
            e.printStackTrace();
            returnnull;
        }
    Movieaudio=null;
    try {
        audio = newMovieCreator().build(audioFile);
    } catch (IOException e) {
        e.printStackTrace();
        returnnull;
    } catch (NullPointerException e) {

        e.printStackTrace();
        returnnull;
    }
    intsize= audio.getTracks().size();
    TrackaudioTrack= audio.getTracks().get((size - 1));
    video.addTrack(audioTrack);

    Containerout=newDefaultMp4Builder().build(video);

    FilemyDirectory=newFile(Environment.getExternalStorageDirectory(), "/Folder Name");
    if (!myDirectory.exists()) {
        myDirectory.mkdirs();
    }
    filePath = myDirectory + "/video" + System.currentTimeMillis() + ".mp4";
    try {
        RandomAccessFileram=newRandomAccessFile(String.format(filePath), "rw");
        FileChannelfc= ram.getChannel();
        out.writeContainer(fc);
        ram.close();
    } catch (IOException e) {
        e.printStackTrace();
        returnnull;
    }
return filePath;
}

In build.gradle add following dependency

compile'com.googlecode.mp4parser:isoparser:1.0.5.4'

Solution 2:

If you want to working with video then you have to use FFMPEG library

That can be you can work with Video.

That for i have already give answer to How to use ffmpeg in android studio? see this LINK. Go step by step and import in your project

Solution 3:

You can use a MediaRecorder without calling setAudio* on it. remove this line

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);

see this link

Solution 4:

There is currently no way to directly record android output without "background noise".

Note that this is a security concern to restrict access to other apps audio output, therefore it is very unlikely that it could be achieved directly.

See this answer

Post a Comment for "How To Video Record With Specific Sound Programmatically In Android?"