Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the problem that I am facing is that other voices such as near by sounds also get recorded. The song file is recorded in the video record screen and I play the song when video recording activity launches.

How can I have my application record only song with video?

 mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
  mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));

Is there any solution in audio source set as a speaker , because song sound going through a speaker? if is it another possible way please reply me.

like image 205
Mayank Sugandhi Avatar asked Feb 18 '16 07:02

Mayank Sugandhi


People also ask

How do I record only internal audio on Android?

Swipe down from the top of your screen to see the quick settings tiles and tap the screen recorder button. A floating bubble will appear with a record and microphone button. If the latter is crossed out, you're recording internal audio, and if it's not, you get sound straight from your phone's mic.

How do I record sound on my Android video?

Tap the Screen Recorder icon and give permission to the device to record the screen (you might have to edit the default icons that appear). Determine what sound, if any, you want recorded. Tap Start recording and a countdown will begin before a toolbar appears on the screen and the recording starts.


3 Answers

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) {
        Movie video = null;
        try {
            video = new MovieCreator().build(videoFile);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    Movie audio = null;
    try {
        audio = new MovieCreator().build(audioFile);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (NullPointerException e) {

        e.printStackTrace();
        return null;
    }
    int size = audio.getTracks().size();
    Track audioTrack = audio.getTracks().get((size - 1));
    video.addTrack(audioTrack);

    Container out = new DefaultMp4Builder().build(video);

    File myDirectory = new File(Environment.getExternalStorageDirectory(), "/Folder Name");
    if (!myDirectory.exists()) {
        myDirectory.mkdirs();
    }
    filePath = myDirectory + "/video" + System.currentTimeMillis() + ".mp4";
    try {
        RandomAccessFile ram = new RandomAccessFile(String.format(filePath), "rw");
        FileChannel fc = ram.getChannel();
        out.writeContainer(fc);
        ram.close();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
return filePath;
}

In build.gradle add following dependency

compile 'com.googlecode.mp4parser:isoparser:1.0.5.4'
like image 145
Muhammad Umair Shafique Avatar answered Sep 21 '22 20:09

Muhammad Umair Shafique


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

like image 44
Ravi Vaghela Avatar answered Sep 22 '22 20:09

Ravi Vaghela


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

mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);

see this link

like image 34
Haniyeh Khaksar Avatar answered Sep 22 '22 20:09

Haniyeh Khaksar