这就是我嵌入视频的方式.它在模拟器中有声音,但在真实设备上没有声音(iOS 9.0.2(13A452))Xcode 7.1.1.
这是我用来播放它的代码:
if let youtubeID = youtubeID { let embededHTML = "" cell!.webView.allowsInlineMediaPlayback = true cell!.webView.scalesPageToFit = true cell!.webView.mediaPlaybackAllowsAirPlay = true cell!.webView.mediaPlaybackRequiresUserAction = false cell!.webView.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL) }
Jincy Varug.. 10
大多数开发人员遇到这个问题,他们忘记
打开iPhone左侧的铃声按钮.它对我有用.
大多数开发人员遇到这个问题,他们忘记
打开iPhone左侧的铃声按钮.它对我有用.
SWIFT 2.0版本我遇到了同样的问题,解决方案是在AppDelegate中添加
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { do { try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback) } catch let error as NSError { print(error) } do { try AVAudioSession.sharedInstance().setActive(true) } catch let error as NSError { print(error) } // Override point for customization after application launch. return true }
这使我的UIWebView中的声音成为可能
我自己找到了答案:这里的解决方案:
if let youtubeID = youtubeID { let embededHTML = " " cell!.webView.allowsInlineMediaPlayback = true cell!.webView.scalesPageToFit = true cell!.webView.mediaPlaybackAllowsAirPlay = true cell!.webView.mediaPlaybackRequiresUserAction = false cell!.webView.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL) }