1

I have used pod youtube-iso-player-helper to integrate YTPlayer within my native iOS application.

The issue, I am facing, is I am not able to hear any sound while the video is being played when the iPhone that has ringer silent & it works fine with earphone but does not work on iPhone speakers.

Note: I have not muted the iPhone volume, it's only ringer silent.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Siddharth Sunil
  • 233
  • 2
  • 10

2 Answers2

1

Objective C:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
playerView.webView.mediaPlaybackRequiresUserAction = NO; 

Swift

let audioSession = AVAudioSession.sharedInstance()
do {
    try audioSession.setCategory(AVAudioSessionCategoryPlayback)
    try audioSession.setActive(true)
} catch {

}

playerView.webView?.mediaPlaybackRequiresUserAction = false
Berlin Raj
  • 124
  • 6
  • The pod I m using does not setup any AVAudioSession, so this solution is not going to work for me. I am using YTPlayerView to play videos, – Siddharth Sunil Aug 01 '17 at 06:53
  • May be YTPlayer-helper does the "[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];" thing internally. but I don't find any thing where I can set this. – Siddharth Sunil Aug 01 '17 at 06:54
  • you can add this code in your view controller class anywhere (for example: viewdidLoad()) – Berlin Raj Aug 01 '17 at 06:54
  • You must add YTPlayerView to a viewController right??, add this code in viewDidLoad() – Berlin Raj Aug 01 '17 at 06:56
  • also disable mediaPlaybackRequiresUserAction property for playerView's webview,.... Please refer above edited code – Berlin Raj Aug 01 '17 at 10:36
1

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];

R.Chauhan
  • 51
  • 1