如何使用youtube-ios-player-helper在Swift中随机播放YouTube播放列表?

时间:2018-07-14 02:12:04

标签: ios swift youtube-api

我正在尝试使用Swift iOS开发中的youtube-ios-player-helper以随机/随机顺序播放一个播放列表,但我似乎不知道该怎么做。

链接到这里:https://github.com/youtube/youtube-ios-player-helper

我在YouTube API文档中检查了playerVars,但这似乎不是一个选择。.所以我想知道这是否有可能?

播放列表本身运行良好,只是顺序没有变化,这是我的代码:

class MusicViewController: UIViewController, YouTubePlayerDelegate {

    @IBOutlet weak var youtubePlayer: YouTubePlayerView!
    @IBOutlet weak var playButton: UIButton!


    override func viewDidLoad() {
        super.viewDidLoad()

        youtubePlayer.delegate = self


        let playerVars = ["playsinline" : "1", "controls" : "0"]
        youtubePlayer.playerVars = playerVars as YouTubePlayerView.YouTubePlayerParameters
        youtubePlayer.loadPlaylistID("PLTzXf6BfROEktE823y4AuhQrvJP2ZuX6q")

        playButton.titleLabel?.font = UIFont.ionicon(of: 38)
        playButton.setTitle(String.ionicon(with: .iosPlay), for: .normal) 
    }

然后点击播放按钮:

@IBAction func play(_ sender: Any) {
        if youtubePlayer.ready {
            if youtubePlayer.playerState != YouTubePlayerState.Playing {
                youtubePlayer.play()
                radioPlaceholder.isHidden = true
                playButton.setTitle(String.ionicon(with: .iosPause), for: UIControlState())
                scheduledTimerWithTimeInterval()
            } else {
                youtubePlayer.pause()
                radioPlaceholder.isHidden = false
                playButton.setTitle(String.ionicon(with: .iosPlay), for: UIControlState())
                timer.invalidate()
            }
        }
    }

如果可能,我如何以及在何处添加此功能...谢谢!

0 个答案:

没有答案