Article

Adding a Now Playing View

Provide a view that controls the currently playing audio from your app.

Overview

Using a Now Playing view, users can control current or recently played audio without leaving your app. To add this view, drag it from the library onto your storyboard, even if you’re building the user interface using SwiftUI.

When your app presents the Now Playing view, it immediately displays information about the current audio source, such as another app on the user’s Apple Watch or iPhone. For example, the Now Playing view lets users pause or play music from the Apple Watch’s Music app or control the volume on a podcast from the iPhone’s Podcast app.

The system automatically selects the source. If the user is listening to audio on their watch or phone, the system selects that audio source. Otherwise, the system selects the most recently used source.

Add the View to Your Storyboard

To add the Now Playing view, drag it from the Library to an empty interface controller in your WatchKit app’s storyboard.

Screenshot showing the Now Playing view inside an interface controller in the storyboard.

Always present the Now Playing view so that it fills the screen in a nonscrolling container. Don’t add any other elements to this scene.

The Now Playing view uses your app’s tint color, but otherwise has no attributes or properties that you can set. In addition, no public interface class exists for the Now Playing view. This means you can’t access or control the view programmatically. Your app just presents the view; the system handles the rest.

Present the View from SwiftUI

When creating a user interface using SwiftUI, you still add the Now Playing view to your storyboard. However, you then use the Identifier from the view’s interface controller to display the view from your SwiftUI code.

A screenshot showing the Now Playing view in the storyboard.

To present the Now Playing view:

  1. Drag an interface controller from the library to the storyboard.

  2. In the Attributes Inspector, set the interface controller’s Identifier to a unique string, such as NowPlaying.

  3. Drag a Now Playing view into the interface controller.

  4. Present the interface controller from your SwiftUI code.

For example, to add a navigation link to the Now Playing view, you create the link using the init(destinationName:label:) initializer.

NavigationLink(destinationName: "NowPlaying") {
                Text("Show Now Playing")
}

Alternatively, you can add the interface controller to a paged navigation that includes one or more SwiftUI hosting controllers.

A screenshot showing the storyboard with a hosting controller and the Now Playing controller set as page navigation.

See Also

Audio

Playing Background Audio

Enable background audio in your app to provide a seamless playback experience.

class WKInterfaceVolumeControl

An interface element that lets users control the audio volume from the watch or a paired iPhone.

class WKAudioFilePlayer

An object that controls playback of a single audio item.

Deprecated
class WKAudioFileQueuePlayer

An object that controls playback of one or more audio items.

Deprecated
class WKAudioFilePlayerItem

An object that manages the presentation state of an audio file while it is being played.

Deprecated
class WKAudioFileAsset

An object that stores a reference to an audio file and provides metadata information about that file.

Deprecated
property list key PUICAutoLaunchAudioOptOut

A Boolean value indicating whether a watchOS app should opt out of automatically launching when its companion iOS app starts playing audio content.

Name: Opt out of Auto-launch Audio App (Watch)