This is strange but this is my project requirement. In my project i want to play a video with audio suppression. For audio we have another plan. So i can use VideoView to play a video. But this plays audio of that file as well(which is not require for me). So how can i achieve this strange requirement, i.e Playing video without audio. http://developer.android.com/reference/android/widget/VideoView.html
You might have turned down the sound and set the device to silent mode for any reason. The phone, therefore, has no sound once you play the video. This can lead to a problem and you might think that the device is out of order when it is not. Turn on the sound from the side button and you are done.
The best way to do this in my opinion is to set the volume to 0 when the video is ready. All the other solutions I've found imply the use of deprecated API which mute the whole system.
This is a simple solution
VideoView videoPreview = (VideoView) findViewById(R.id.video_view);
videoPreview.setOnPreparedListener(
new MediaPlayer.OnPreparedListener()
{
@Override
public void onPrepared(MediaPlayer mp)
{
mp.setVolume(0f, 0f);
}
}
);
This link Supplying option to user to play video with or without audio helped me to mute my video's sound. Then by using MediaExtractor, AudioTrack API(s) i can extract audio samples from file and then i can play those extracted samples using AudioTrack object. Only precaution that i have to take is while creating AudioTrack object use AudioManager.STREAM_RING
audioTrack= new AudioTrack(AudioManager.STREAM_RING, 44100, AudioFormat.CHANNEL_OUT_STEREO, AudioFormat.ENCODING_PCM_16BIT, 44100, AudioTrack.MODE_STREAM);
So videoView plays my video but i can't hear audio because STREAM_MUSIC is in mute, audioTrack object plays my audio separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With