MediaPlayer events

MediaPlayer has two groups of events:

1) has a handler like

func(MediaPlayer)

You can also use func(). This group includes the following events:

  • "abort-event" (constant AbortEvent) - Fires when the resource is not fully loaded, but not as a result of an error.
  • "can-play-event" (CanPlayEvent constant) is fired when the user agent is able to play mediabut judges that there is not enough data loaded to play the media to the end withouthaving to stop to further buffer the content.
  • "can-play-through-event" (constant CanPlayThroughEvent) is fired when the user agent is ableto play the media and evaluates that enough data has been loaded to play the media to its end,without having to stop to further buffer the content.
  • "complete-event" (CompleteEvent constant) -
  • "emptied-event" (EmptiedEvent constant) is fired when the media becomes empty; for example when the media is already loaded (or partially loaded)
  • "ended-event" (EndedEvent constant) - Fires when playback stops, when the end of media is reached, or if no further data is available.
  • "loaded-data-event" (LoadedDataEvent constant) is fired when the first frame of the media has finished loading.
  • "loaded-metadata-event" (LoadedMetadataEvent constant) is fired when the metadata has been loaded.
  • "loadstart-event" (LoadStartEvent constant) is fired when the browser starts loading the resource.
  • "pause-event" (PauseEvent constant) is fired when a pause request is processed and the action pauses, most often when the Pause () method is called.
  • "play-event" (PlayEvent constant) is fired when the media file starts playing, for example, as a result of using the Play () method
  • "playing-event" (PlayingEvent constant) is fired when playback is about to start after being paused or delayed due to lack of data.
  • "progress-event" (ProgressEvent constant) is fired periodically when the browser loads the resource.
  • "seeked-event" (SeekedEvent constant) is fired when the playback speed has changed.
  • "seeking-event" (SeekingEvent constant) is fired when a seeking operation begins.
  • "stalled-event" (StalledEvent constant) is fired when the user agent tries to retrieve media data, but no data arrives unexpectedly.
  • "suspend-event" (SuspendEvent constant) is fired when media loading has been suspended.
  • "waiting-event" (WaitingEvent constant) is fired when playback is stopped due to a temporary lack of data

2) has a handler like

func(MediaPlayer, float64)

You can also use func(float64), func(MediaPlayer) and func().This group includes events related to changing the parameters of the player.The new value of the changed parameter is passed as the second argument.

  • "duration-changed-event" (DurationChangedEvent constant) is fired when the duration attribute has been updated.
  • "time-updated-event" (TimeUpdatedEvent constant) is fired when the current time has been updated.
  • "volume-changed-event" (VolumeChangedEvent constant) is fired when the volume changes.
  • "rate-changed-event" (RateChangedEvent constant) is fired when the playback speed has changed.

A separate event that does not belong to these two groups, "player-error-event" (PlayerErrorEvent constant)is fired when the resource cannot be loaded due to an error (eg network error).

The handler for this event looks like

func(player MediaPlayer, code int, message string)

You can also use func(int, string), func(MediaPlayer) and func().Where the argument "message" is the error message, "code" is the error code:

Error code Constant Value
0 PlayerErrorUnknown Unknown error
1 PlayerErrorAborted Fetching the associated resource was interrupted by a user request.
2 PlayerErrorNetwork Some kind of network error has occurred that prevented the media from successfully ejecting, even though it was previously available.
3 PlayerErrorDecode Although the resource was previously identified as being used, an error occurred while trying to decode the media resource.
4 PlayerErrorSourceNotSupported The associated resource object or media provider was found to be invalid.