Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only video, no audio

Tags:

android

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

like image 747
saa Avatar asked Dec 27 '13 07:12

saa


People also ask

Why is a video playing without sound?

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.


2 Answers

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);
                    }
                }
        );
like image 119
Angelo Nodari Avatar answered Nov 13 '22 04:11

Angelo Nodari


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.

like image 1
saa Avatar answered Nov 13 '22 04:11

saa