iOS Developer Library

Developer

MediaPlayer Framework Reference MPMediaPlayback Protocol Reference

Options
Deployment Target:

On This Page
Language:

MPMediaPlayback

Inheritance


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import MediaPlayer

Objective-C

@import MediaPlayer;

Availability


Available in iOS 3.2 and later.

The MPMediaPlayback protocol defines the interface adopted by the MPMoviePlayerController class for controlling media playback. This protocol supports basic transport operations including start, stop, and pause, and also lets you seek forward and back through a movie or to a specific point in its timeline.

  • play() - play Required

    Initiates playback of the current item. (required)

    Declaration

    Swift

    func play()

    Objective-C

    - (void)play

    Discussion

    If playback was previously paused, this method resumes playback where it left off; otherwise, this method plays the first available item, from the beginning.

    If a movie player is not prepared for playback when you call this method, this method first prepares the movie player and then starts playback. To minimize playback delay, call the prepareToPlay method before you call this method.

    To be notified when a movie player is ready to play, register for the MPMoviePlayerLoadStateDidChangeNotification notification. You can then check load state by accessing the movie player’s loadState property.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • pause() - pause Required

    Pauses playback of the current item. (required)

    Declaration

    Swift

    func pause()

    Objective-C

    - (void)pause

    Discussion

    If playback is not currently underway, this method has no effect. To resume playback of the current item from the pause point, call the play method.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • stop() - stop Required

    Ends playback of the current item. (required)

    Declaration

    Swift

    func stop()

    Objective-C

    - (void)stop

    Discussion

    This method stops playback of the current item and resets the playhead to the start of the item. Calling the play method again initiates playback from the beginning of the item.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Prepares a movie player for playback. (required)

    Declaration

    Swift

    func prepareToPlay()

    Objective-C

    - (void)prepareToPlay

    Discussion

    If a movie player is not already prepared to play when you call the play method, that method automatically calls this method. However, to minimize playback delay, call this method before you call play.

    Calling this method may interrupt the movie player’s audio session. For information on interruptions and how to resond to them, see Audio Session Programming Guide.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • A Boolean value indicating whether a movie player is ready to play. (required) (read-only)

    Declaration

    Swift

    var isPreparedToPlay: Bool { get }

    Objective-C

    @property(nonatomic, readonly) BOOL isPreparedToPlay

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Begins seeking backward through the media content. (required)

    Declaration

    Swift

    func beginSeekingBackward()

    Objective-C

    - (void)beginSeekingBackward

    Discussion

    Use this method to move the current playback position backward in time at an accelerated rate. Seeking begins when you call this method and continues until you call the endSeeking method.

    If the underlying content is streamed, this method has no effect.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Begins seeking forward through the media content. (required)

    Declaration

    Swift

    func beginSeekingForward()

    Objective-C

    - (void)beginSeekingForward

    Discussion

    Use this method to move the current playback position forward in time at an accelerated rate. Seeking begins when you call this method and continues until you call the endSeeking method.

    If the underlying content is streamed, this method has no effect.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • Ends forward and backward seeking through the media content. (required)

    Declaration

    Swift

    func endSeeking()

    Objective-C

    - (void)endSeeking

    Discussion

    You must call this method to end a seeking operation begun by calling either the beginSeekingBackward or beginSeekingForward method. After calling this method, the player returns to the same state it was in prior to seeking. In other words, if the item was playing before seeking began, it continues playing from the new playhead position after calling this method.

    If the underlying content is streamed, this method has no effect.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The current playback rate for the player. (required)

    Declaration

    Swift

    var currentPlaybackRate: Float { get set }

    Objective-C

    @property(nonatomic) float currentPlaybackRate

    Discussion

    This value represents a multiplier for the default playback rate of the current item. A value of 0.0 indicates that playback is stopped while a value of 1.0 indicates that playback is occurring at normal speed. Positive values indicate forward playback while negative values indicate reverse playback.

    Setting the value of this property changes the playback rate accordingly.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.

  • The current position of the playhead. (required)

    Declaration

    Swift

    var currentPlaybackTime: NSTimeInterval { get set }

    Objective-C

    @property(nonatomic) NSTimeInterval currentPlaybackTime

    Discussion

    For video-on-demand or progressively downloaded content, this value is measured in seconds from the beginning of the current item. Changing the value of this property moves the playhead to the new location. For content streamed live from a server, this value represents the time from the beginning of the playlist when it was first loaded.

    Import Statement

    Objective-C

    @import MediaPlayer;

    Swift

    import MediaPlayer

    Availability

    Available in iOS 3.2 and later.