-
Coordinate media experiences with Group Activities
Discover how you can help people watch or listen to content all in sync with SharePlay and the Group Activities framework. We'll show you how to adapt a media app into a synchronized, SharePlay-enabled experience for multiple people. Learn how to add Group Activities to your app, explore the Picture in Picture layout, and find out how the playback coordinator object can help you fine-tune playback across multiple devices.
Ressources
Vidéos connexes
WWDC22
WWDC21
-
Rechercher dans cette vidéo…
-
-
3:06 - Define a GroupActivity
protocol GroupActivity: Codable { /// An identifier so the system knows how to reference this activity static var activityIdentifier: String { get } /// Information that the system uses to show this activity, such as title and a preview image var metadata: GroupActivityMetadata { get async } } -
4:42 - Making your play buttons automatically start a group session when appropriate
func playButtonTapped() { let activity = MovieWatchingActivity(movie: movie) Task { switch await activity.prepareForActivation() { case .activationDisabled: // Playback coordination isn't active. Queue movie // for local playback. self.enqueuedMovie = movie case .activationPreferred: // Activate the activity. The system enqueues the movie // when the activity starts. activity.activate() case .cancelled: // The user cancelled the operation. Nothing to perform. break default: break } } } -
8:31 - Receiving a GroupSession from the GroupSession AsyncSequence
// Receiving a GroupSession from the GroupSession AsyncSequence func listenForGroupSession() { Task { for await session in MovieWatchingActivity.sessions() { ... } } } -
9:03 - Attaching an AVPlayer to the GroupSession
let player = AVPlayer() ... func listenForGroupSession() { Task { for await groupSession in MovieWatchingActivity.sessions() { // Verify content is available, prepare for playback to begin player.playbackCoordinator.coordinateWithSession(groupSession) ... } } } -
31:26 - Custom suspensions
class AVPlaybackCoordinator { func beginSuspension(for reason: AVCoordinatedPlaybackSuspension.Reason) -> AVCoordinatedPlaybackSuspension } class AVCoordinatedPlaybackSuspension { func end() func end(proposingNewTime newTime: CMTime) }
-