View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Videos

Abrir menú Cerrar menú
  • Colecciones
  • Todos los videos
  • Información

Más videos

  • Información
  • Código
  • Explore media metadata publishing and playback interactions

    Learn how you can highlight your app's Now Playing information on every platform. We'll take you through an overview of media metadata, learn how it gets represented in areas like the Lock Screen and Control Center, and show you how to write and publish effective media metadata for your content. We'll also explore how your app can respond to commands from other devices such as HomePod.

    Recursos

    • Media Player
      • Video HD
      • Video SD

    Videos relacionados

    WWDC22

    • Create a great video playback experience
  • Buscar este video…
    • 4:34 - Instantiation examples

      // playing Magnificent
      
      self.session = MPNowPlayingSession(players: [player])
      
      
      
      // Playing different WWDC sessions, one full screen and one in PiP
      
      self.session = MPNowPlayingSession(players: [player])
      self.pipSession = MPNowPlayingSession(players: [pipPlayer])
      
      
      
      // playing multi-view race
      
      self.session = MPNowPlayingSession(players: [topLeft, topRight, bottomLeft, bottomRight])
    • 4:58 - Promoting and demoting sessions as Now Playing

      // Promoting and demoting sessions as Now Playing
      
      self.session = MPNowPlayingSession(players: [player])
      self.pipSession = MPNowPlayingSession(players: [pipPlayer])
      
      // if the content in PiP is promoted to full screen, swap active
      
      self.pipSession.becomeActiveIfPossible { becameActive in
          // if success, pipSession data populates lock screen, etc, and
          // controls from lock screen, etc are routed to pipSession
      }
    • 5:32 - Responding to play and pause commands

      // Example of responding to play and pause commands
      
      self.session = MPNowPlayingSession(players: [player])
      
      // respond to play commands
      self.session.remoteCommandCenter.playCommand.addTarget { event in
          player.play()
          return .success
      }
      
      // respond to pause commands
      self.session.remoteCommandCenter.pauseCommand.addTarget { event in
          player.pause()
          return .success
      }
    • 6:22 - Responding to skip forward commands

      // Example responding to skip forward commands
      
      self.session.remoteCommandCenter.skipForwardCommand.preferredIntervals = [15.0]
      self.session.remoteCommandCenter.skipForwardCommand.addTarget { event in
          let skipCommand = event as! MPSkipIntervalCommandEvent
          player.seek(to: CMTimeAdd(player.currentTime(), CMTimeMakeWithSeconds(skipCommand.interval, preferredTimescale: 1)))
          return .success
      }
      
      // commands can also be disabled. for example, during an ad:
      self.session.remoteCommandCenter.skipForwardCommand.isEnabled = false
      
      // add handlers for all commands that are applicable to the content
// https://developer.apple.com/documentation/mediaplayer/mpremotecommandcenter
    • 7:48 - Setting artwork metadata with automatic publishing

      // Example of setting artwork metadata
      let artwork = MPMediaItemArtwork(image: image)
      let title = "Magnificent"
      
      playerItem.nowPlayingInfo = [
          MPMediaItemPropertyTitle: title,
          MPMediaItemPropertyArtwork: artwork,
          // …
      ]
      
      self.session = MPNowPlayingSession(players: [player])
      self.session.automaticallyPublishNowPlayingInfo = true
    • 8:38 - Setting ad time ranges for automatic publishing

      // Example with ads that should not contribute to elapsed time and duration
      
      let preroll = MPAdTimeRange(timeRange: CMTimeRange(start: CMTime.zero, duration: CMTimeMakeWithSeconds(30, preferredTimescale: 1)))
      
      
      playerItem.nowPlayingInfo = [
          …
          MPNowPlayingInfoPropertyAdTimeRanges: [preroll]
          …
      ]
      
      self.session = MPNowPlayingSession(players: [player])
      self.session.automaticallyPublishNowPlayingInfo = true
    • 11:02 - Setting artwork and title metadata for AVKit

      // Example of setting artwork metadata
      
      let path = Bundle.main.path(forResource: "poster", ofType: "jpg")
      let posterData = FileManager.default.contents(atPath: path!)!
      
      let artwork = AVMutableMetadataItem()
      artwork.identifier = .commonIdentifierArtwork
      artwork.value = posterData as NSData
      artwork.dataType = kCMMetadataBaseDataType_JPEG as String
      artwork.extendedLanguageTag = "und"
      
      let title = AVMutableMetadataItem()
      title.identifier = .commonIdentifierTitle
      title.value = "Magnificent" as NSString
      title.extendedLanguageTag = "und"
      
      playerItem.externalMetadata = [artwork, title]
    • 12:59 - Manually publishing Now Playing

      // Example of setting Now Playing information
      
      let artwork = MPMediaItemArtwork(image: image)
      
      let nowPlayingInfo = [
          MPMediaItemPropertyTitle: title,
          MPMediaItemPropertyArtwork: artwork,
          MPMediaItemPropertyPlaybackDuration: playerItem.duration,
          MPNowPlayingInfoPropertyElapsedPlaybackTime: player.currentTime().seconds,
          MPNowPlayingInfoPropertyPlaybackRate: player.rate
      ]
      
      MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
    • 13:25 - Updating Now Playing metadata

      // On any non-linear time change, playback rate change, or play/pause
      
      var nowPlayingInfo = MPNowPlayingInfoCenter.default().nowPlayingInfo
      nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = player.currentTime().seconds
      nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate

Developer Footer

  • Videos
  • WWDC22
  • Explore media metadata publishing and playback interactions
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & 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
    • Mini Apps Partner 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
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines