无法在tvOS中播放YouTube视频.得到“操作要求客户数据源已经被注册". [英] Can't play a YouTube video in tvOS. Got a "Operation requires a client data source to have been registered"
问题描述
当我尝试在tvOS中播放YouTube视频时,出现以下错误:
When I try to play a YouTube video in tvOS I get the following error:
[MediaRemote] [MRPlaybackQueueServiceClient] playingQueueRequest AFCF4995-D293-4B5B-82F0-E701186F639F PineBoard-21384 /A600.000000x600.000000/R[0:1]回应了资产请求,但发生了错误 错误域= kMRMediaRemoteFrameworkErrorDomain代码= 15操作 要求已注册客户数据源." UserInfo = {NSLocalizedDescription =操作需要客户端数据 来源已注册.}
[MediaRemote] [MRPlaybackQueueServiceClient] playbackQueueRequest AFCF4995-D293-4B5B-82F0-E701186F639F PineBoard-21384 /A600.000000x600.000000/R[0:1] responded to asset request with error Error Domain=kMRMediaRemoteFrameworkErrorDomain Code=15 "Operation requires a client data source to have been registered." UserInfo={NSLocalizedDescription=Operation requires a client data source to have been registered.}
我正在使用XCDYouTubeKit库.
I'm using the XCDYouTubeKit library.
产生错误的代码是:
let playerViewController = AVPlayerViewController()
self.present(playerViewController, animated: true, completion: nil)
weak var weakPlayerViewController: AVPlayerViewController? = playerViewController
XCDYouTubeClient.default().getVideoWithIdentifier("9bZkp7q19f0") { video, error in
if (video != nil) {
let streamURLs = video?.streamURLs
var streamURL: URL?
if (streamURLs?[XCDYouTubeVideoQualityHTTPLiveStreaming] != nil) { streamURL = streamURLs?[XCDYouTubeVideoQualityHTTPLiveStreaming] }
else if (streamURLs?[XCDYouTubeVideoQuality.HD720.rawValue] != nil) { streamURL = streamURLs?[XCDYouTubeVideoQuality.HD720.rawValue] }
else if (streamURLs?[XCDYouTubeVideoQuality.medium360.rawValue] != nil) { streamURL = streamURLs?[XCDYouTubeVideoQuality.medium360.rawValue] }
else if (streamURLs?[XCDYouTubeVideoQuality.small240.rawValue] != nil) { streamURL = streamURLs?[XCDYouTubeVideoQuality.small240.rawValue] }
if let streamURL = streamURL {
weakPlayerViewController?.player = AVPlayer(url: streamURL)
weakPlayerViewController?.player?.play() // HERE IS WHERE I GET THE ERROR
}
}
}
我不明白为什么会出现此错误. 甚至,如果我在XCDYouTubeKit存储库中运行tvOS演示代码,我也会遇到相同的错误.
I don't understand why I get this error. Even, If I run the tvOS demo code inside the XCDYouTubeKit repository I also get the same error.
推荐答案
将以下内容添加到appDelegate.swift应该可以修复错误:
Adding the following to appDelegate.swift should fix the error:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(.playback, mode: .moviePlayback)
}
catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
return true
}
这篇关于无法在tvOS中播放YouTube视频.得到“操作要求客户数据源已经被注册".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!