Skip to main content

Code samples (MediaPlayerCoreX engine, cross-platform)

Introduction

This page contains several small tutorials with code samples for the MediaPlayerCoreX engine.

How can I play back a part of the source file?

You can enable fragment playback by setting the segment start and stop time.

// create new instance of MediaPlayerCoreX
MediaPlayerCoreX MediaPlayer1 = new MediaPlayerCoreX(VideoView1);

// set the source file
var fileSource = await UniversalSourceSettings.CreateAsync(new Uri("video.mkv"));
await MediaPlayer1.OpenAsync(fileSource);

//set start time to 5000 ms
MediaPlayer1.Segment_Start = TimeSpan.FromMilliseconds(2000);

// set stop time to 10000 ms
MediaPlayer1.Segment_Stop = TimeSpan.FromMilliseconds(5000);

// start playback
await MediaPlayer1.PlayAsync();

Reverse video playback

To use reverse playback, set the rate to a negative value. Use the -2.0 value to play the video in reverse at double speed.

// create new instance of MediaPlayerCoreX
MediaPlayerCoreX MediaPlayer1 = new MediaPlayerCoreX(VideoView1);

// set the source file
var fileSource = await UniversalSourceSettings.CreateAsync(new Uri("video.mp4"));
await MediaPlayer1.OpenAsync(fileSource);

// start playback
await MediaPlayer1.PlayAsync();

// set rate to -1.0
MediaPlayer1.Rate_Set(-1.0);

Visit our GitHub page to get more code samples.