MediaEvents

The MediaEvents class provides a set of events and methods for handling media-related events in your application. Below is a detailed reference for each property, event, and method available in the MediaEvents class.

Properties

Error

  • Description: Gets the last error message from the native plugin.

  • Type: string

  • Usage:

    string errorMessage = MediaEvents.Error;

IsInitialized

  • Description: Indicates whether the media player is initialized.

  • Type: bool

  • Usage:

    bool isInitialized = MediaEvents.IsInitialized;

Events

onIsBufferingChanged

  • Description: Event triggered when the buffering state changes.

  • Type: Action<bool>

  • Usage:

    MediaEvents.onIsBufferingChanged += (isBuffering) => {
        // Handle buffering state change
    };

onIsPlayingChanged

  • Description: Event triggered when the playing state changes.

  • Type: Action<bool>

  • Usage:

    MediaEvents.onIsPlayingChanged += (isPlaying) => {
        // Handle playing state change
    };

onIsLoadingChanged

  • Description: Event triggered when the loading state changes.

  • Type: Action<bool>

  • Usage:

    MediaEvents.onIsLoadingChanged += (isLoading) => {
        // Handle loading state change
    };

onInitialized

  • Description: Event triggered when the media player initialization state changes.

  • Type: Action<bool>

  • Usage:

    MediaEvents.onInitialized += (isInitialized) => {
        // Handle initialization state change
    };

onPrepared

  • Description: Event triggered when the media player is prepared.

  • Type: Action

  • Usage:

    MediaEvents.onPrepared += () => {
        // Handle media player prepared
    };

onComplete

  • Description: Event triggered when the media playback is complete.

  • Type: Action

  • Usage:

    MediaEvents.onComplete += () => {
        // Handle playback complete
    };

onError

  • Description: Event triggered when an error occurs.

  • Type: Action<string>

  • Usage:

    MediaEvents.onError += (error) => {
        // Handle error
    };

onDownloadProgress

  • Description: Event triggered to report download progress.

  • Type: Action<string, float>

  • Usage:

    MediaEvents.onDownloadProgress += (fileName, progress) => {
        // Handle download progress
    };

onPlaylistUpdated

  • Description: Internal event triggered when the playlist is updated.

  • Type: Action

  • Usage:

    // This event is for internal use and should be handled accordingly.

Methods

SyncMediaDataOnReturn

  • Description: Syncs media data when returning to the app.

  • Usage:

    csharp코드 복사MediaEvents.SyncMediaDataOnReturn();

GetPlayerName

  • Description: Gets the name of the player based on the platform and URI type.

  • Type: string

  • Usage:

    string playerName = MediaEvents.GetPlayerName();

OnUnityReceiveMessage

  • Description: Handles messages received from Unity.

  • Usage:

    MediaEvents.OnUnityReceiveMessage("ON_INIT_CHANGED_TRUE");

OnIsBufferingChangedFalse

  • Description: Manually triggers the buffering state to false.

  • Usage:

    MediaEvents.OnIsBufferingChangedFalse();

OnError

  • Description: Manually triggers an error event.

  • Usage:

    MediaEvents.OnError("Error message");

OnDownloadProgress

  • Description: Manually triggers a download progress event.

  • Usage:

    MediaEvents.OnDownloadProgress("filename_0.5"); // 50% progress

Example Usage

Here's an example of how you might use the MediaEvents class in your application:

using Glitch9.NativePlugins.NativeMediaPlayer;

public class MediaPlayerExample : MonoBehaviour
{
    void Start()
    {
        // Subscribe to events
        MediaEvents.onInitialized += OnInitialized;
        MediaEvents.onIsPlayingChanged += OnIsPlayingChanged;
        MediaEvents.onError += OnError;
    }

    void OnInitialized(bool isInitialized)
    {
        Debug.Log($"Media Player Initialized: {isInitialized}");
    }

    void OnIsPlayingChanged(bool isPlaying)
    {
        Debug.Log($"Is Playing: {isPlaying}");
    }

    void OnError(string error)
    {
        Debug.LogError($"Media Player Error: {error}");
    }
}

This API reference provides detailed information on each property, event, and method available in the MediaEvents class, along with their usage examples. This should help users understand and utilize the features of your media player effectively.

Last updated