Reputation: 2562
When I run the following code in my iOS simulator I get sound from the embed YouTube video. When I run this on my iPhone 6 I get no sound coming from the speakers but I do get sound from the headphones. Is this a hardware issue or is it software?
import UIKit
class ThreeKeyViewController: UIViewController {
@IBOutlet weak var videoView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let youTubeUrl = "https://www.youtube.com/embed/hP-vuMaoHjU"
videoView.allowsInlineMediaPlayback = true
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.videoView.loadHTMLString("<iframe width=\"\(self.videoView.frame.width)\" height=\"\(self.videoView.frame.height)\" src=\"\(youTubeUrl)\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)
print("This is run on the main queue, after the previous code in outer block")
})
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
Upvotes: 1
Views: 230
Reputation: 2562
SWIFT 2.0 version I have the same problem for me the solution was to add in the AppDelegate. Thanks to Daleks. Must not forget to Import AVFoundation.
Import UIKit
import AVFoundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
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)
}
return true
}enter code here
Upvotes: 1