在后台Swift中播放YouTubePlayer声音 [英] Playing YouTubePlayer Sound in Background Swift

查看:300
本文介绍了在后台Swift中播放YouTubePlayer声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用YouTubeSDK在我的应用中播放YouTube视频: https:// github.com/gilesvangruisen/Swift-YouTube-Player

I'm using the YouTubeSDK to play YouTube videos in my app found here: https://github.com/gilesvangruisen/Swift-YouTube-Player

然而,当用户按下主页时,我希望声音继续在后台播放。
https://github.com/youtube/youtube-ios -player-helper / issues / 38

However, when the user presses home I want the sound to keep playing in the background. https://github.com/youtube/youtube-ios-player-helper/issues/38

我目前正在 App Delegate 中尝试此操作(code> didFinishLaunchingWithOptions : b

I'm currently trying this in the App Delegate (awful conversion) in the didFinishLaunchingWithOptions:

let sessionEror:NSError?
do {

    let playBG = try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .DefaultToSpeaker)

} catch let error as NSError  {
    print("ERROR")
}

这是它自己的功能相同的文件:

And this is in it's own function in the same file:

func playerView(YTPlayerView: YTPlayerState, didChangeToState: YTPlayerState) {

        switch {

        case YTPlayerState.Paused:
            YTPlayerState.Playing,
        break
        }


    }

您是否知道如何使用YouTube SDK在后台继续播放声音?此外,是否可以在后台播放声音并视频?

Any idea how to keep playing the sound in the background using the YouTube SDK? Also, is it possible to just play the sound in the background and not the video?

欢迎任何和所有帮助。

Any and all help is appreciated.

推荐答案

分离Youtube视频的视频和音频是针对 YouTube服务条款。在禁止下查看

Separating out the video and audio of a Youtube video is against YouTube Terms of Service. Look under Prohibitions



  1. 分离,隔离或修改音频或视频通过YouTube API提供的任何YouTube视听内容的组件;

  1. separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API;

分别宣传通过YouTube API提供的任何YouTube视听内容的音频或视频组件;

promote separately the audio or video components of any YouTube audiovisual content made available through the YouTube API;


话虽如此,解决方法仍然与解释此处此处均表示你需要有一个代理视频播放的服务。直接,Youtube API不允许您这样做。

That being said, the workaround still remains the same as explained here or here which both suggest that you need to have a service that delegates the video's playback. Directly, the Youtube API will not allow you to do so.

这篇关于在后台Swift中播放YouTubePlayer声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆