1120是什么星座| 异禀是什么意思| 淋巴滤泡形成什么意思| 夏天适合吃什么菜| 虫草有什么功效| 睾丸长什么样子| 2岁什么都听懂但不说话| 雷诺氏病是一种什么病| 小猫什么时候可以洗澡| 总蛋白偏高有什么危害| 肋软骨炎吃什么药| 宝宝风寒感冒吃什么药最好| 池鱼是什么意思| 牙周炎是什么症状| senda是什么牌子| 拉雪橇的狗是什么狗| 男孩子断掌有什么说法| 色令智昏是什么意思| 小孩流鼻血吃什么好| 得五行属什么| ex是什么意思| 均字五行属什么| 女人肾虚吃什么好得快| 鳊鱼吃什么食物| 减肥晚上吃什么合适| 周杰伦为什么叫jay| 脚趾头麻木是什么原因引起的| 泌乳素高有什么影响| 什么才是真正的情人| 惊恐症是什么病| 为什么要坐月子| 来日方长是什么意思| 智齿疼吃什么药最管用| 卡司是什么意思| 枸杞泡茶喝有什么功效| 硕字五行属什么| 大姨妈来能吃什么水果| 手表seiko是什么牌子| 知是什么意思| 屎是黑色的是什么原因| 认知障碍是什么病| 去湿气喝什么好| 高密度脂蛋白胆固醇低是什么意思| 什么是代谢| 孕妇为什么不能吃西瓜| 血脂高低看什么指标| 什么心什么心| 无底洞是什么意思| 甲沟炎应该挂什么科| 有什么笑话| 什么澎湃| 迪丽热巴颜值什么水平| 猪精是什么| 85年属什么的生肖| 唇红齿白是什么生肖| 喝柠檬水有什么作用与功效| 驾照c2能开什么车| 圣诞节是什么时候| sheen是什么牌子的手表| 大麦茶有什么功效与作用| 男生眉毛浓黑代表什么| 胃疼是什么原因| 李宁是什么牌子| 流清口水是什么原因| 逸五行属性是什么| 8月3号是什么星座| 展望未来什么意思| 泰坦尼克号什么时候上映的| 羊球是什么| 短板是什么意思| 条线是什么意思| 腹痛吃什么药| 三七花泡水喝有什么功效和作用| 63岁属什么| 常州冬至吃什么| 贵格是什么意思| 孙权与孙策是什么关系| 疏通血管吃什么好| 急性鼻窦炎吃什么药| 元气大伤什么意思| 来大姨妈不能吃什么| 后脑勺发麻是什么原因| 夜间睡觉口干是什么原因| 锁骨下面的骨头叫什么| 手机壳什么材质最好| 梦见粽子是什么预兆| 橡皮泥可以做什么| 鹌鹑蛋不能和什么一起吃| 建档需要什么资料| 劲仔小鱼是什么鱼做的| 白塞氏病是什么病| 咳嗽发烧是什么原因| 抖m什么意思| 这是什么虫| 手掉皮是缺什么维生素| 副词什么意思| 原则上是什么意思| 什么的绽放| 为什么喝咖啡会心慌| 栋梁之材是什么意思| 百思不得其解什么意思| 生眼屎是什么原因引起的| 低血糖会出现什么症状| 碳是什么| 黑海为什么叫黑海| 女生什么时候最容易怀孕| 什么光没有亮度| 刚愎自用代表什么生肖| 白癜风有什么危害| 30如狼40如虎是什么意思| 莎字五行属什么| 总是心慌是什么原因| 獭尾肝是什么病| 鼠配什么生肖最好| 针对性是什么意思| 验血肝功能看什么指标| 肺大泡是什么原因造成的| guess是什么品牌| 什么是电子烟| 狗狗咳嗽吃什么药好得快| 胆结石忌吃什么| 为什么同房后小腹隐隐作痛| 黄豆煲汤搭配什么最好| 菠萝蜜什么季节最好吃| 心急如焚是什么意思| 严重失眠挂什么科| 十一月一日是什么星座| 鸡精和味精有什么区别| bra什么意思| 孕妇吃核桃对胎儿有什么好处| ecl是什么意思| 什么叫散瞳| 什么泡酒让性功能最强| 属虎的幸运色是什么颜色| 月经稀发是什么意思| 流鼻血是什么引起的| 7月14日是什么日子| 什么样的水花| 视力突然模糊是什么原因引起的| 白带异常是什么原因| 天成是什么意思| 结晶是什么意思| 两个a型血的人生的孩子什么血型| 孤独的最高境界是什么| 做流产手术需要准备什么东西| 面包虫吃什么| 贾宝玉大名叫什么| 长生是什么意思| 8月30号是什么星座| 人艰不拆是什么意思| 结膜出血是什么原因| 活泼的近义词是什么| 乳腺钙化灶是什么意思| 气管炎吃什么药| 为什么会得痔疮| loves是什么意思| 所谓是什么意思| 吃什么容易长高| 格力空调睡眠模式1234什么意思| 珍珠疹是什么原因引起的| 黄色裤子搭配什么颜色上衣| 男人有霉菌是什么症状| 尿白细胞3十什么意思| 海蜇是什么动物| 4月10日什么星座| 扁桃体有什么作用| 啪啪啪是什么意思| 血糖高什么原因引起| 跌水是什么意思| 什么方法可以促进睡眠| 寒咳吃什么药| 岁月如歌什么意思| 校正是什么意思| 思字属于五行属什么| 黄酒有什么功效与作用| 潜水是什么意思| 涤塔夫是什么面料| 常州为什么叫龙城| 一什么所什么| 铁是什么颜色的| 糖耐量受损是什么意思| 男性硬下疳是什么样子| 尿酸高是什么症状| 痈疡是什么意思| 奥运五环绿色代表什么| 为什么这么热| 学什么设计最赚钱| 喝什么补肾| 数字五行属什么| kids是什么牌子| 支原体感染咳嗽吃什么药| 色弱和色盲有什么区别| hvb是什么意思| 清道夫吃什么| 抑郁症看什么科| 小学教师需要什么学历| 主管药师是什么职称| 齐多夫定片是治什么病的| 仪表堂堂是什么生肖| 凤梨和菠萝有什么区别| 葵水是什么| 为什么会起鸡皮疙瘩| 相向而行是什么意思| 晟这个字念什么| 皇汉是什么意思| 血糖高喝酒有什么影响| 左胸隐隐作痛是什么原因| 暗示是什么意思| 睡眠不好挂什么科门诊| 连什么带什么| 12月14日什么星座| 女人梦见掉头发是什么征兆| 脂肪粒是什么原因引起的| 朱迅和朱军是什么关系| 淋巴挂什么科| a7是什么意思| 小猫打什么疫苗| 7.13是什么日子| 氨基丁酸是什么| 姨妈的老公叫什么| 酒糟是什么东西| 一什么不什么| 倒模是什么意思| 180度是什么角| 床上什么虫子夜间咬人| 1986年虎是什么命| 羊驼为什么吐口水| 1984年是什么年| 豆汁是什么味道| 电视黑屏是什么原因| 白带有腥味是什么原因| 什么减肥药好使| 孩子咳嗽吃什么药效果好| 什么饼不能吃脑筋急转弯| 音什么笑什么成语| 紫色睡莲的花语是什么| 胶原蛋白有什么作用| 嵌合体是什么意思| 孕妇dha什么时候开始吃| 为什么睡不着觉会胡思乱想| 肚子疼应该吃什么药| 静息心率是什么意思| 肉桂属于什么茶| 三月二十八号是什么星座| 蚝油是什么做的| 什么远什么长| 下午5点是什么时辰| 免疫抑制剂是什么意思| 祥五行属什么| 吃什么抑制食欲| 凉粉什么做的| 月字旁的字与什么有关| 向心性肥胖是什么意思| 女人吃桃子有什么好处和坏处| 腹泻吃什么水果| 牛黄解毒片不能和什么药一起吃| remax是什么牌子| 男性性功能障碍吃什么药| 梦见把头发剪短了是什么意思| 乳清是什么| 月经腰疼是什么原因引起的| 上颌窦囊肿是什么意思| 2012属什么生肖| 春天开的花都有什么花| 百度

View in English

  • Global Nav Open Menu Global Nav Close Menu
  • Apple Developer
Search
Cancel
  • Apple Developer
  • News
  • Discover
  • Design
  • Develop
  • Distribute
  • Support
  • Account
Only search within “”

Quick Links

5 Quick Links

Videos

Open Menu Close Menu
  • Collections
  • Topics
  • All Videos
  • About

More Videos

  • About
  • Transcript
  • 关于开展2016年河北省优秀旅游新闻作品评选的通知

    百度 以人为本,人品第一,比赛第二才是一名合格的运动员应具备的素质。

    AVKit is a high-level framework for building media user interfaces, complete with playback controls, chapter navigation, Picture-in-Picture, audio routing, support for subtitles and closed captioning, Siri and Now Playing integration, and support for keyboard, Touch Bar, and remote control. Learn best practices in how to integrate these technologies into your own apps on iOS, tvOS, and iPad apps on Mac.

    Resources

    • AVPlayerViewController
      • HD Video
      • SD Video
    • Presentation Slides (PDF)

    Related Videos

    WWDC21

    • Deliver a great playback experience on tvOS
    • What's new in AVKit

    WWDC20

    • Master Picture in Picture on tvOS

    WWDC19

    • Reaching the Big Screen with AirPlay 2
  • Search this video…

    Welcome to Delivering Intuitive Media Playback with AVKit. My name is Jed Lewison, and I'll be joined a little bit later by my colleague Dan Wright. And we're going to talk with you about media playback with AVKit. And what's new in best practices with AVPlayerViewController on iOS and tvOS.

    AVKit is a cross platform media playback UI framework built on top of AVFoundation in CoreMedia. And our mission is to make it easy for you to show and play AVPlayer-based media content using the same user interface used by Apple's own apps.

    For UIKit apps, we provide AVPlayerViewController.

    For APKit apps, we provide AVPlayerView. And for both UIKit and APKit apps, we provide AVRoutePickerView, which lets you add a wireless route picker to your custom playback UI's.

    So let's take a look at some code. Getting started with AVPlayerViewController on iOS is incredibly easy, and tvOS. The first thing you do is you create an AVPlayer.

    Then, you create and AVPlayerViewController and assign to it the player that you just created.

    And finally, you present it. And that's all there is to it.

    That's all it takes to get a rich and fully functional media playback UI that will be familiar to your users because it's the same UI used by Apple in its own apps. But there's a lot of power below the surface. And that's because when you use AVKit, you own the media playback objects. You are in control of creating and managing them. And video rendering is built on top of the same core technology that powers AVPlayerLayer.

    That means you get the full power of AVFoundation in CoreMedia playback UI's, including all the power delivered by AVPlayer, AVPlayerItem, and AVAsset. But because AVKit also sit on top of UIKit and AppKit, you get a user experience tailored to each of Apple's unique platforms. So AVKit gives you the best of both worlds.

    You get full control over your media playback objects. And a familiar API for showing and displaying them using UIKit and APKit-based APIs.

    So, that's a high-level look at AVKIt. Let's dive right into what's new in AVPlayerViewController and iOS for iOS 13. I'm going to start talking about new full screen callbacks that we added that inform you about transitions from embedded inline presentations to full screen and entering full screen and exiting full screens. So, to motivate this, in this video, what we'll see is the user's going to enter full screen here and then start an interactive dismissal. But, they'll cancel that dismissal. So now we're back to full screen. And now the user has dismissed, and we're back to where we started with an AVPlayerViewController embedded inline.

    So, the new API we're delivering in iOS 13 informs you about all of these states by extending AVPlayerViewController Delegate.

    You get notifications when a full screen presentation begins or ends. And it looks like this.

    Two new delegate methods.

    If you link against the iOS 13 SDK, they will be available starting with iOS 12, one for beginning a full screen presentation, and one that is called when a full screen presentation ends.

    So, let's take a look at an implementation here. And the key object is the UIViewControllerTransition Coordinator. At that works exactly the same as it does with any other view controller transition in UIKit. And you can learn about all those details and the power there from UIKit documentation. But the key thing I want to focus on here is the completion handler for the animate alongsideTransition callback. And this is where you find out whether a transition succeeded or whether the user cancelled it. And this is the source of truth for learning about entering full screen from an inline presentation.

    And obviously it's interesting to know whether the player view controller is full screen or whether it is embedded inline. But why is it crucial? It's important because, let's take the case of where your player view controller may have been in a scroll view. And the user has entered full screen. When the device rotates, as you know, sometimes your scroll view's offset might change. And it's possible that the player view controller will scroll offscreen.

    And that's okay for it to scroll offscreen during the full screen presentation because the user can't see it. But you need to make sure that the player view controller does stay alive. If it is deallocated, the full screen presentation will end. So you can use the new API to know when to take a strong reference to the player view controller if your table view controller or collection view happens to remove the player view controller if it's scrolled offscreen. But you're still left with the question of how do you get it back in place when the user exits full screen. And for that, you use the willEnd variant of the new API. And this is called the before the animation begins. So you can reset the location of the player view controller in your UI. And the user will be none the wiser. Everything will be back the way they expect.

    So those are full screen callbacks.

    Now let's take a look at AVPlayerViewController in iPad apps on the Mac. And as you know, iPad apps can now be built on the Mac. And AVPlayerViewController is a full participant in that.

    And here's what it looks like. You get the same user interface that you expect from Apple's playback UIs with all the functionality that AVPlayerViewController delivers for iPad apps. But you also get some platform specific features for Mac. Things like touch bar support, which you get for free.

    And keyboard support.

    And we've also added picture-in-picture support to iPad apps on the Mac. In fact, we've extended picture-in-picture support to all UIKit and APPKit-based apps on the Mac for this release.

    And how many new lines of code to you need to use AVPlayerViewController in an iPad app on the Mac? You guessed it. None.

    So that's AVPlayerViewController and iPad apps on the Mac.

    Now let's talk about external metadata. And to motivate this, imagine that your AirPlaying content. And imagine when you did that, your locked screen looked like this, instead of like this. And there's two things that make it possible to show this UI. The first thing is you need to handle remote control commands. And AVKit handles that for you automatically for free. You don't have to do anything.

    But you also sometimes have media that doesn't have all the metadata that you would want to publish baked in. And for that, we're adding this new API to iOS. It's actually existed on tvOS. And you take your AVPlayerItem. And you can supplement metadata with things like title, metadata, or artwork metadata. It's super easy. And when you do that, we'll take care of the rest. We've also, in iOS 13, improved support for interactive -- for custom controls from AVPlayerViewController. That's always been possible to do, use custom controls with AVPlayerViewController on iOS. But when you did that, you lost all the other things that weren't onscreen. Things like interactive dismissals. Or landscape support.

    Things like keyboard. And now in AVPlayerViewController on iPad apps for the Mac, touch bar support. So, what you can do now in iOS 13 is if you set showsPlaybackControls to False.

    And then you present AVPlayerViewController modally.

    And finally use the contentOverlayView as a place where you place your custom controls.

    You can have a completely custom playback UI but still take advantage of things like nowPlayingInfo support and interactive dismissals. But there's some things, if you do this, some things you should keep in mind. You still are going to need to take care of status bar and home indicator appearance. And you should always pass unhandled touches through your view hierarchy so that AVKit can handle things like interactive dismissals or double-tap for zoom, which we'll talk about in a little bit.

    So, that's a look at what's new in AVPlayerViewController on iOS. There's a bunch more things that we've added.

    And one of them is we've made great strides in improving performance in iOS 12. And it's even better on iOS 13. So if you're interested in using AVPlayerViewController in scroll view, it should be buttery smooth now.

    So, let's talk about some best practices with AVPlayerViewController.

    I want to talk about three different ways that we show video on our devices. And of course, there's a fourth way that we show video from an iOS device AirPlay. And there was a terrific talk on Tuesday morning at 9:00 a.m. If you haven't seen it, I would strongly recommend watching that talk. But I'm going to focus on on-device playback today.

    And let's start with full screen video playback. And of course, what I mean by that is full screen in the UIKit sense of the word. So, we're talking about covering your UIWindowScene coordinate space. And if we think about it, there's two different reasons why we might play a video full screen. It could be for sort of a background video in a splash screen scenario. Or because the video is the star of the show. And we want full playback controls. And let's take a quick look at the splash screen scenario. And you're going to have set of these things that you're going to want to implement in your application.

    And to do that, you're going to take the playerViewController. You're going to embed it as a child. So it can be at the bottom of your view hierarchy. You're going to do things like disabling playback controls and setting the video gravity so that the video scales to fill the full screen.

    If you're using the new video with alpha APIs that are new in this release, you're going to want to set your view's background color to clear or some other color to leverage that.

    And there's some things to take into account with AVFoundation. You always want to make sure to prevent external playback with something that is playing as a splash screen. Because you don't want to interrupt, say, music playing on someone's Apple TV. And you want to configure the audio session. And especially this last property on AVAudioSession, that this secondary audio should be silenced. It lets you know if the user is playing audio from some other application. And they want that application to be -- that audio to be primary. In that case, if you have audio in your splash screen video, make sure to mute it.

    But then, let's look at full screen playback where the video is the star of the show. And when we do this, of course we want playback UI that adapts beautifully whether it's a portrait presentation like this where we have a stacked playback transport controls. Or we're in landscape and we need a slightly different layout but the same -- but we need to deliver the same functionality. So AVPlayerViewController delivers this to you for free. And it also does things like, you'll notice in those two screen shots the video was unzoomed in portrait. And now it's zoomed in landscape.

    And it's zoomed to fill the entire screen because the user has generally, in this case, has played video that is of similar aspect ratio to the device aspect ratio in a zoomed format. But some users prefer to have video unzoomed, like here. And when that happens we want to make sure that the video isn't occluded by any physical characteristic of the device. AVKit is aware of all these things and takes care of that for you when you're using PlayerViewController. But rather than running through every feature that we provide, I just want to zoom in on two very small things that we added in iOS 13. The first -- in this video, you're going to hear audio playing. And the user's going to tap the Mute button. Notice when it mutes, there's a subtle ramp to the audio. And there's an animation in the volume slider.

    And then in this example, there's an interactive dismissal. And notice that the audio gracefully fades with the user's dismissal. And then when the user cancels the dismissal, the audio comes back up.

    So those are two small things, but they illustrate the level of attention to detail that we're able to give to AVPlayerViewController and that your users will get for free if you're able to adopt it in your app.

    You get a whole bunch of other things. And the question that you might ask is how do you get all of this? And let's take another look at code.

    So, this is basically the same thing that I showed earlier in the talk. The only addition is this external metadata. This line allows you to supplement your metadata. And it really is that easy to get started.

    But it's worth talking about why it's possible for you to do so little on the UI side and to get such a good experience. And so, for that I want to talk about a couple of best practices here. So, when you use AVPlayerViewController for a full screen presentation you should always present it modally, not as a child view controller of some other view controller. And sometimes you may have done that because you wanted to learn about presentation state, which you can now do with the callbacks that I discussed earlier.

    Presenting modally lets us handle things like status bar visibility. Let's us optimize the screen's display mode. It lets us handle video gravity, video zoom mode, interactive dismissals. And when you are presenting modally full screen, you should use the default modal presentation style. As you may know, in iOS 13, the new default modal presentation style is automatic. And what that resolves to for AVPlayerViewController is a full screen presentation.

    And there's two types of full screen presentations: Full screen and over full screen. The reason why you want to use the default is because when your view controller is presented, the presenting view can be removed by UIKit. This allows, because your view is covering the newly presented view hierarchy, removing the presenting view is an optimization during rotation. You don't want to do layout when your view's not even visible. But it also allows things like landscape playback if your app is otherwise portrait only or this view controller hierarchy is otherwise portrait only.

    It's also best just to leave the video gravity property alone for full screen playback. That allows us to do automatic behaviors like I was illustrating before. If you set the video gravity, we'll give you exactly what you want. We'll zoom the video or unzoom the video. But once you do that, the automatic behavior, we can't do the automatic behavior anymore. So your users generally would prefer to have the automatic behavior. And of course, use the new delegate methods to track the full screen presentation state.

    A couple of tips related to AVFoundation best practices here. What this one is about, the way I think about it, is if you're starting a video, say halfway into the video, seek the player item to the resume time before setting it on the player. And make sure you're going to have a playing player that it's already playing. And then provide that to AVPlayerViewController. And this allows the UI to look correct. And more importantly, it avoids loading content that isn't going to end up being played.

    You should also always observe AVPlayer's and AVPlayerItem status property.

    Though you can use KVO to observe them. When they fail, when the property status becomes failed, there's an easy path to recovery in many cases. Check the error property. See if media services were reset. And if so, just rebuild your player, player item, your AVFoundation object ref and set it back on the PlayerViewController and everything should be fine. And this property gives you an optimized video rendering when you're mirroring. And of course, always configure your audio session for playback.

    So, when we talk about embedding AVPlayerViewController inline, there's a little bit more to consider.

    And we've already talked about the full screen, new full screen presentation state callbacks in iOS 13.

    So I won't go over those again. But, one thing I want to touch on is if you've used AVPlayerViewController in the past, when we enter full screen from an embedded inline presentation, the modal transition style has been in over full screen style, which means that your view, your presenting view, isn't removed. If your app links against iOS 13, the default presentation style now will be full screen. Which means that the presenting view might be removed. And that has all the benefits that I talked about earlier.

    So, ideally you'll be able to leave this modal presentation style as full screen. But if you don't, it's okay. You can still set it to over full screen. But the recommendation is to just stick with the default.

    Another thing to consider is when you have an embedded presentation, your video, you may want to zoom the video so that you don't have black bars on top or on bottom. You also might want to have things like a corner curve to the video's view port. And also, you may want to set the background color of the view. You can do all that to AVPlayerViewController's view or to the video gravity when it's embedded inline. And we'll use that for the inline part of the presentation. If the user decides to go full screen, then we'll do the right thing there. So, in contrast to, if you're just presenting AVPlayerViewController full screen, it's okay to -- you can change these properties for the inline portion of the presentation. No problem at all.

    We also have a couple of properties that provide automatic behavior when you have an inline presentation. And these allow you to do things like, if the user taps a big play button, the PlayerViewController will -- the content of the PlayerViewController will automatically enter full screen.

    And similarly, at the end of the video, will exit full screen. And it's really best for us to handle those things on your behalf. Because for example, let's say that a user is scrubbing to the end of a video.

    Well, the time's going to be the end of the video, but you don't want to dismiss the video at that point. Because they're probably just seeking around. We keep track of what the user is doing. And we'll only exit if it's appropriate.

    Of course, you're always going to want to adopt UIViewController containment API. And it looks like this.

    One other thing to keep in mind is if you have a lot of videos that you're scrolling through, you may find that having a poster image is a good idea as a way to show a frame of the video without having to have the video fully loaded. And that can take a little bit of time. And so you use AVPlayerViewController's contentOverlayView for this. But then you want to know when is the video -- when is the first frame of video ready so that you can remove the content that you just put in the overlay view.

    You do that by observing isReadyForDisplay on AVPlayerViewController. It's a property that you can observe using KVO. And this is what it looks like to observe it. You always want to take the initial value because it could be the video frame is already rendered.

    I want to finish by talking a little bit about picture-in-picture, which is super easy to add to your app. AVPlayerViewController takes care of most things for you. You do have to configure your application to support picture-in-picture. And it looks like this. Just click a check box in XCode.

    One thing, this applies whether you're using AVPictureInPictureController or AVPlayerViewController. When a user swipes up to go home in iPad, picture-in-picture may automatically start. And that means when your app is entering background, you should not pause any playing video. Because picture-in-picture may be starting. You don't want to pause the very video that your user is trying to keep on watching. So, don't pause. And AVFoundation will take care of this for you. But if you absolutely must pause, you should wait for the application's background state, application state, or the window scene state to reach background. And this is how you do that.

    You can track state about whether you're in picture-picture or leaving picture-picture using the AVPlayerViewControllerDelegate.

    And always toggle PictureInPicture Playback.

    Be prepared for your view controller to dismiss when picture-in-picture is starting. And unlike in the full screen case, we will prevent deallocation of AVPlayerViewController while picture-in-picture is active. But if the view controller's been dismissed, you're going to want to restore the UI when the user wants to go back to your app. And so, it's really easy to do that. This is the callback you're going to get AVPlayerViewControllerDelegate. And all you have to do here is get your UI back into a state that works, that is what you want. In this case we're just presenting the view controller again. And then when you're ready, call the completion handler that is passed into the callback. Let us know that you're ready to go. And we will animate back in place. You need to do it fairly quickly, otherwise the picture-in-picture window might just go oop! And no more picture-in-picture for your user. And they're not able to get back to your app.

    So, that's a look at what's new in best practices for AVPlayerViewController in iOS. There's sample code illustrating all these concepts at our session website. And now, I'd like to hand things over to my colleague, Dan Wright.

    All right. Let's talk about video playback on TV.

    On tvOS AVPlayerViewController supports full screen interactive playback with standard controls for navigation, information, and settings.

    Built in support for advanced Siri features such as "what did she say?" Publication of Now Playing info. Interstitials such as for ads. Content proposals, and more.

    So, what's new for tvOS 13? Since last year we've updated the appearance of the controls. And starting with tvOS 12.3, introduced fine precision scrubbing.

    Today, we're introducing custom interactive overlays, channel flipping for live streams, and automatic enforcement of parental content restrictions.

    Fine precision scrubbing makes it easier to use your Siri remote to find the precise moment in the video that you're looking for.

    PlayerViewController has always supported -- the scrubbing in PlayerViewController has always made it easy to navigate quickly across a wide range of your video. But now fine scrubbing makes it easier to find a very precise moment, like within about a second, as you're navigating.

    And of course, the info views have a new appearance to match the TV app.

    Custom interactive overlays support application controls. A custom overlay is normally hidden.

    A hint onscreen guides the user to swipe up, which presents your overlay. The overlay is fully interactive, and it can contain buttons, collections, or any other interactive elements that you like as defined by your view controller. And then you should, for persistent non-interactive elements like a channel logo, for example, you should continue to use the contentOverlayView too. Let's see what custom overlays look like. When the video begins, you have a hint at the bottom to guide them to swipe up for more. And when they swipe up, they get your overlay. Just like that. They can dismiss by swiping down or by clicking the Menu button.

    So, your view controller is presented. You get all the usual UIViewController notifications. We handle dismissal and animations. And your users get a consistent experience across applications. So all you need to do to use it is to define your view controller with the content that you want to display. And set the customOverlayViewController property on your player view controller.

    Live broadcast channel flipping.

    Channel flipping is for live streams. It provides support for flipping between multiple live streams. For example, different channels. The user swipes horizontally to go to the next or the previous channels.

    And a channel interstitial screen describes each channel while it loads. So let's see what channel flipping looks like. As the user swipes between channels, your channel interstitial view is shown.

    Here it has a simple green background, some text, and a loading indicator. But, that's entirely within your control. You can make it look whatever you like in there, including pictures, a gradient background, your custom spinner, whatever you like. The main thing is to orient your user to where they are and where they're going.

    And the one other thing I would add is that this a non-interactive screen. It's meant to guide the user to the next channel. So you shouldn't expect to have controls here. To support channel flipping, extend your AVPlayerViewControllerDelegate to implement playerViewController skipToNextChannel and skipToPreviousChannel.

    All these methods do is replace the content in your player view controller with that of the new channel. You can wait until the content is ready to play if you like.

    When you're done, call the completion block. Pass True if it was successful. And pass False if something failed.

    But whatever you do, make sure that you call that completion block eventually, because that's what's going to dismiss the channel interstitial.

    Now, there are two additional methods: nextChannelInterstitialView Controller and previousChannelInterstitialView Controller. And these are responsible for providing that view controller that displays between channels.

    So, you need to instantiate your view controller, if you have one, if you need to. And populate it with information about the new channel.

    And then just return it. In this example we're instantiating a new view controller every time. But in many cases, you could probably just instantiate it once and then reuse it.

    tvOS has built in support for restricting access to content using a passcode, or with a device profile. Device profiles are commonly used in a classroom setting or perhaps a business setting.

    In tvOS 13, AVKit provides automatic support to help your users regain control of restricted content. So, to test content restrictions, go to Settings, Restrictions.

    Turn them on. Provide and confirm a passcode.

    Then change the allowed content rating under Movies, and/or TV Shows.

    In this case we'll change it to PG-13.

    So, what do you need to do to actually support it in your app? Well, the most important thing is you need to specify the media content rating in all of your content. If your asset does not have this information, then you'll need to add it using the external metadata property of AVPlayerItem. And you're going to want to use the iTunes metadata content rating identifier.

    You'll want to provide this rating at the start of playback so that AVKit can test whether this is restricted content according to the user settings.

    And present the passcode to screen if necessary.

    Now, if the content is restricted by passcode, the user will be prompted to enter it.

    If it is restricted by a device profile, however, it could simply fail to play entirely. There may be no option for the user to override.

    Now, AVPlayerViewController will request access automatically to your content when playback begins. But you can request access earlier using a new API request playback restrictions authorization.

    And of course, any kind of failure here, if the user doesn't know the passcode or doesn't want to enter the passcode, or if it's a device profile that prohibits it, the player view controller will be automatically dismissed. And finally, if you have a custom playback user interface, you can also request access using the aforementioned API to restricted content. Now let's take a look at what the user sees when attempting to play restricted content. Now, the video's going to load. And as soon as it's ready to play and the metadata's available, the passcode screen is going to immediately appear. And as soon as the user enters the passcode, the passcode screen is dismissed and the video begins playing. So let's take a look at how to provide the media content rating.

    This metadata is sometimes part of your assets. But usually it is not.

    So you will need to provide it via the external metadata property of the AVPlayerItem. We've seen this code before in previous presentations. But we just have a helper function here that takes our rating in the form of a string and returns and AVMetadataItem.

    The value is that string. The extended language tag is set to und for Undefined because it's not any particular language.

    Your identifier is the iTunesMetadataContent Rating.

    And then finally, once we've created it, in this case with a rating of PG-13, we add it to the external metadata property of the player item. Now, AVPlayerViewController will prompt automatically, if necessary. But let's say you want to prompt earlier before you present the player view controller, or perhaps before earlier content. You can do this using the requestPlayback Restrictions Authorization API on AVPlayerItem. The closure will be called when the request is complete to indicate whether there the request succeeded or failed.

    And if it fails, the error provides information about why it failed. If it succeeded, you should proceed with playback. Otherwise, you should cancel, dismiss, go back to your menu screen or whatever. And don't try to play the content again unless the use explicitly requests it.

    All right. Let's do a brief demo and get a closer look at some of this.

    All right. So we have our little sample app.

    These videos may be familiar to some of you who have done testing with HLS.

    Here's our swipe up. Swipe for more hints at the bottom. And if we swipe up, we get our custom overlay. And see that it actually works and everything. And I can just swipe down to get rid of it. And what else do we have here? Well, if I press and keep my finger down, we see the Hints on the left and the right sides of the screens. Those are the arrows to guide the user to channel flipping. And if I just swipe -- see what's going on next door.

    Using some great design patterns, including -- Oh yeah, it's the bottom part is using a list to lay out -- In the last month -- Let's see. What else do we have? Is that it? Oh, what's going on over here? All right.

    All right. So we have our little sample app.

    I passed me. Let's go back to -- let's see -- back to the -- Here's our Swipe up bar for more hints at the bottom.

    And if we swipe up, we get our custom overlay and see if it actually works -- Let's pause.

    All right. So let's take a moment to talk about some best practices on tvOS now.

    Some of you already have controls in your apps that are revealed by swipe up. Often, it's Up Next list.

    And typically, you're doing this by installing your own custom swipe up gesture recognizer on the player view or a super view. And then presenting your view controller. Well, if you're doing that, we want to encourage you to migrate to using a custom overlay instead.

    What that gets you is much better compatibility in the future -- hint. And a better and more consistent experience for your users across applications. If you're using a UI tap gesture recognizer on the Menu button to detect dismissal of your player view controller, or in some cases to provide the dismissal animation, you should use the delegate to dismissal notifications instead. We introduced those in tvOS 11. And they should give you all the information that you need. This is important because it's no longer the case that the only way that your play view controller can be dismissed is by the user hitting the Menu button. It could now be automatically dismissed.

    I've said this one before, but showsPlaybackControls should not be abused to try to force immediate change in the visibility of the controls. The purpose of showsPlaybackControls is to configure the player view controller to indicate whether you want the user to have access to the playback controls at all.

    Provide media content ratings for all of your content.

    And of course, test with parental content restrictions enabled.

    Most of you will have no issues, but you might find that there's something that you're doing that doesn't work very well when a passcode stream comes up. For example, if you display a hint for a few seconds at the start of playback, you would want to not do that while the passcode is covering it or the user won't see it.

    So in summary, adopt AVPlayerViewController across platform. You get great functionality on iOS and on tvOS for a very low cost.

    And a wide range of compatibility for remotes and other features.

    Use AVPlayerViewControllerDelegate notifications to track presentation state, as seen today on iOS, and to handle dismissal, as on tvOS. Observe the player item status and handle errors.

    Use external metadata, now on both iOS and tvOS in addition to some of these uses we've seen today for parental content restrictions and in the info panel. External metadata is also used to publish Now Playing info, which means that if you use external metadata on both platforms, you can now remove all of your Now Playing info support.

    If you have a custom overlay on a swipe up action, migrate it -- I'm sorry -- if you swipe up action presenting an overlay, migrate to custom overlays.

    And finally, support parental content restrictions.

    So, for more information, including sample code for this session, visit our session page at the URL on the screen. And come with your questions and your code to the AVKit Lab at 2:00 p.m. today or to the AVFoundation lab at 4:00. Thank you, and enjoy the rest of conferences. [ Applause ]

Developer Footer

  • Videos
  • WWDC19
  • Delivering Intuitive Media Playback with AVKit
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • App Extensions
    • App Store
    • Audio & Video
    • Augmented Reality
    • Design
    • Distribution
    • Education
    • Fonts
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning
    • Open Source
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Tutorials
    • Downloads
    • Forums
    • Videos
    Open Menu Close Menu
    • Support Articles
    • Contact Us
    • Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Get the Apple Developer app.
    Copyright ? 2025 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines
    三星堆为什么叫三星堆 老子叫什么名字 2011年是什么生肖 精液是什么形成的 囟门是什么意思
    吃什么药可以减肥 鬼针草有什么作用 white是什么意思颜色 px是什么单位 大哥是什么生肖
    网球肘用什么膏药效果好 中暑是什么原因 肉桂有什么作用 马齿苋有什么功效 9月出生的是什么星座
    吃维生素b12有什么好处和副作用 大便不成形吃什么中成药 牙齿痛是什么原因 胯骨疼是什么原因 字形是什么意思
    松果体囊肿是什么病clwhiglsz.com 鸭子为什么会游泳aiwuzhiyu.com 吃什么最补血而且最快hcv9jop2ns8r.cn 吃虾不能吃什么clwhiglsz.com 细菌性阴道炎有什么症状hcv9jop2ns5r.cn
    葡萄糖偏低是什么意思yanzhenzixun.com 总胆红素偏高是什么意思hcv9jop2ns4r.cn veromoda是什么牌子hcv7jop7ns0r.cn 窦性心律什么意思hcv9jop3ns4r.cn 得不偿失是什么意思hcv8jop5ns8r.cn
    今天属什么生肖老黄历hcv9jop1ns6r.cn 痛风是什么hkuteam.com 什么人不能喝咖啡luyiluode.com 对公转账是什么意思liaochangning.com 身上出现白块什么原因hcv8jop3ns5r.cn
    滑精是什么原因ff14chat.com 叶酸每天什么时候吃最好hcv8jop1ns2r.cn 八哥吃什么食物hcv9jop1ns4r.cn 白血病是什么症状hcv8jop3ns1r.cn 臭氧是什么hcv9jop4ns4r.cn
    百度