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

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

问题描述

刚刚开始接触AVKit,而我试图播放一些音频。这将是不错的使用掌握现代媒体播放所以新AVPlayerViewController我有一个现成的播放/暂停/寻求UI。我基本上都与它有一个嵌入SEGUE到AVPlayerViewController容器视图故事板。然后我用:

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.

推荐答案

为什么要推倒重来?只要继承 AVPlayerViewController ,并使用其 contentOverlayView 属性。在这里你可以设置一个专辑封面图片,或将任何的UIView QuickTime的标志(如视频会),与对照组之间。

Why reinvent the wheel? Just subclass AVPlayerViewController and use its 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头:

AVPlayerViewController Header:

/*!
    @property   contentOverlayView
    @abstract   Use the content overlay view to add additional custom views between the video content and the controls.
 */
public var contentOverlayView: UIView? { get }

您的子类:

import UIKit
import AVKit

class MyAVPlayerViewController: AVPlayerViewController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        let albumArt = UIImageView(image: UIImage(...))
        self.contentOverlayView?.addSubview(albumArt)
        // tweak your image frame here as-needed
    }
}

请注意,你必须经过这样做的 AVPlayerViewController 已经被presented,因为它的 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天全站免登陆