Skip to content

Instantly share code, notes, and snippets.

@troy-lamerton
Last active March 20, 2021 18:22
Show Gist options
  • Save troy-lamerton/c3e0952cb8b5d8181bf3cd7fe2086631 to your computer and use it in GitHub Desktop.
Save troy-lamerton/c3e0952cb8b5d8181bf3cd7fe2086631 to your computer and use it in GitHub Desktop.

Methods

public static class CosMediaPlayer {

    /// <summary>
    /// Set the shown video and optionally the preloading video url.
    /// </summary>
    /// <remarks>
    /// If the video at `videoUrl` is already playing, it will continue playing.
    /// You can specify PlaybackOptions to mute the already playing video.
    ///
    /// CosMediaPlayer.SetMediaSources can be called at any time
    /// If the current page in the UniWebview is e.g. https://twitch.tv/sodapoppin,
    /// then the replays html page is loaded.
    /// </remarks>
    public static void SetMediaSources(string videoUrl, PlaybackOptions options, string playerKind, string? preloadingVideoUrl = null)

    // ...
}

// The UniWebView that CosMediaPlayer uses is set through this method.
public class WebViewMedia {
    public static void ReplaceWebViewForMedia(UniWebView? webView)
    
    // ...
}

Play one replay

var myReplay = "https://cosvods.com/cdn/replay/cos-bob/vodid100/hls_multi/master.m3u8";

// large replay player overlay
CosMediaPlayer.SetMediaSources(myReplay, PlaybackOptions.Default, PlayerKind.replays);

// feed player overlay
CosMediaPlayer.SetMediaSources(myReplay, PlaybackOptions.Default, PlayerKind.feedAutoplay);

Example of preloading

var replay1 = "https://cosvods.com/cdn/replay/cos-alice/vod111/hls_multi/master.m3u8";
var replay2 = "https://cosvods.com/cdn/replay/cos-bob/vod222/hls_quick/playlist.m3u8";

CosMediaPlayer.SetMediaSources(replay1, PlaybackOptions.Default, PlayerKind.feedAutoplay, replay2);
// *replay1 starts playing as soon as its loaded*

// some time later...

CosMediaPlayer.SetMediaSources(replay2, PlaybackOptions.Default, PlayerKind.feedAutoplay);
// *replay2 starts playing immediately* (it already finished loading)
// OR *replay2 starts playing as soon as its loaded* (it was only partly loaded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment