Search code examples
androidyoutube-apiandroid-youtube-api

How to mute a Youtube Video by using Youtube API v3?


I'm using Youtube Api V3 for playing a video in my android App. However, I'm using Text to speech along with the video, so I would like to mute the video so that the other audio is audible.

I've searched the documentation and internet, but found solution only for javascript. Any help would be appreciated. Thanks.


Solution

  • I Still haven't found the exact solution to mute the Youtube Video using the Api.

    Instead, Here's the work-around solution I've reached, in my case. Hope it might be helpful for someone else.

    I've set the TTS Stream to STREAM_ALARM.(refer this question)

    HashMap<String, String> params = new HashMap<>();
    params.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
    
    textToSpeech.speak("Hello World", TextToSpeech.QUEUE_FLUSH, params);
    

    Now I Mute the SREAM_MUSIC Volume and I got the result I wanted. Anyone got better Ideas are more than welcome.

    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    if (am != null) {
        am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
    }