AVPlayerViewController 使用纯音频 AVPlayer [英] AVPlayerViewController using audio-only AVPlayer

查看:22
本文介绍了AVPlayerViewController 使用纯音频 AVPlayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用 AVKit,我正在尝试播放一些音频.使用 掌握现代媒体播放中详述的新 AVPlayerViewController 会很好我有一个现成的播放/暂停/搜索用户界面.我基本上有一个带有容器视图的故事板,它具有到 AVPlayerViewController 的嵌入 segue.然后我使用:

Just starting out with AVKit, and I'm trying to play some audio. It would be nice to use the new AVPlayerViewController detailed in Mastering Modern Media Playback so that I have a ready-made play/pause/seek UI. I basically have a storyboard with a container view which has an embed segue to the AVPlayerViewController. Then I use:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "embedAudio") {
        var playerViewController:AVPlayerViewController = segue.destinationViewController as AVPlayerViewController

        playerViewController.player = AVPlayer(URL: NSURL(string: "http://dts.podtrac.com/redirect.mp3/files.serialpodcast.org/sites/default/files/podcast/1420057326/serial-s01-e01.mp3"))
    }
}

它可以很好地嵌入和播放,但在视频所在的位置有一个大的黑色 QuickTime 符号.我想知道是否有办法让它看起来更像音乐或播客应用.

It embeds nicely and plays, but it has a big black QuickTime symbol where the video would be. I'm wondering if there's a way to make it look more like the Music or Podcasts app.

推荐答案

为什么要重新发明轮子?只需使用 AVPlayerViewControllercontentOverlayView 属性.您可以在此处设置专辑插图图像,或在 QuickTime 徽标(视频所在的位置)和控件之间放置任何 UIView.

Why reinvent the wheel? Just use AVPlayerViewController's contentOverlayView property. Here you can set an album artwork image, or place any UIView between the QuickTime logo (where the video would be), and the controls.

请注意,您必须在 AVPlayerViewController 出现后执行此操作,因为它的 contentOverlayView 属性在 prepareForSegue

Note that you must do this after the AVPlayerViewController has been presented, as its contentOverlayView property will be nil in prepareForSegue

这篇关于AVPlayerViewController 使用纯音频 AVPlayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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