This is how I embed my video. It has sound in the simulator, however has no sound on a real device (iOS 9.0.2 (13A452)) Xcode 7.1.1.
This is the code I use to play it:
if let youtubeID = youtubeID {
let embededHTML = "<html><body><iframe src=\"http://www.youtube.com/embed/\(youtubeID)?playsinline=1\" width=\"\(width)\" height=\"\(height)\" frameborder=\"0\" allowfullscreen></iframe></body></html>"
cell!.webView.allowsInlineMediaPlayback = true
cell!.webView.scalesPageToFit = true
cell!.webView.mediaPlaybackAllowsAirPlay = true
cell!.webView.mediaPlaybackRequiresUserAction = false
cell!.webView.loadHTMLString(embededHTML, baseURL: NSBundle.mainBundle().bundleURL)
}
Most developers come across this issue they forget to
switch on the ringer button on the left side of your iPhone.
It worked for me.
SWIFT 2.0 version I have the same problem for me the solution was to add in the 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
}
This enable sound in my UIWebView
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