问题
I'm working on an iOS app that can display YouTube videos in a UIWebView. Everything is working great except...
The first time a video is played it plays at ~10% volume. The device volume is set at 100% and the player volume shows 100% in the UI. Backing out of the web view and play a song in the app using our native streaming player then go back to the video it plays at the correct volume.
Things that don't work...
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[MPMusicPlayerController applicationMusicPlayer] setVolume:1.0];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[MPMusicPlayerController iPodMusicPlayer] setVolume:1.0];
}
Both calls just flash the volume changed UI on screen and do nothing for the WebView volume.
If you have any ideas that would be greatly appreciated.
回答1:
After some more research I just needed to set the playback type back from the built in audio player.
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
Something along those lines.
来源:https://stackoverflow.com/questions/14445418/embedded-uiwebview-youtube-volume