2016-07-18 6 views
1

Когда я запускаю следующий код в своем iOS-симуляторе, я получаю звук от встроенного видео YouTube. Когда я запускаю это на своем iPhone 6, я не получаю звука от динамиков, но я получаю звук из наушников. Это аппаратная проблема или это программное обеспечение?Отсутствует звук из встроенного видео YouTube

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. 
} 

ответ

1

СВИФТ версии 2.0 У меня такая же проблема для меня решение было добавить в AppDelegate. Благодаря Далексу. Не забывайте импортировать 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 
Смежные вопросы