I'm using youtube-ios-player-helper to play youtube video in my application. I'd like to be able to mute. Here is what I did:
Add setVolume() and mute() function in YTPlayerView
-(void)setVolume:(int)volume {
if ( volume < 0 )
volume = 0;
else if ( volume > 100 )
volume = 100;
NSString *command = [NSString stringWithFormat:@"player.setVolume(%d);", volume];
[self stringFromEvaluatingJavaScript:command];
}
-(void)mute {
NSString *command = [NSString stringWithFormat:@"player.mute();"];
[self stringFromEvaluatingJavaScript:command];
}
Then I call setVolume:0 or mute functions in my app. But the sound can't be turned off. The volume is still 100.
Did anybody turn off the sound successfully?
Following the above I got it working in Swift4:
func playerView(_ playerView: YTPlayerView, didChangeTo state: YTPlayerState) {
if case .playing = state {
playerView.webView?.stringByEvaluatingJavaScript(from: "player.mute();")
}
}
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