Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MediaDataStream を使う
public class MyMediaPlayer
{
private Android.Media.MediaPlayer MediaPlayerInstance { get; set; }
public void CreateMediaPlayer()
{
this.MediaPlayerInstance = new Android.Media.MediaPlayer();
}
public void Play(System.IO.Stream stream)
{
var source = new StreamMediaDataSource(stream);
this.MediaPlayerInstance.Reset();
this.MediaPlayerInstance.SetDataSource(source);
this.MediaPlayerInstance.Prepare();
this.MediaPlayerInstance.Start();
}
}
public class StreamMediaDataSource : Android.Media.MediaDataSource
{
private System.IO.Stream MediaStream { get; }
public override long Size => this.MediaStream.Length;
public StreamMediaDataSource(System.IO.Stream stream)
{
this.MediaStream = stream;
}
public override void Close()
{
this.MediaStream.Close();
}
public override int ReadAt(long position, byte[] buffer, int offset, int size)
{
// 読み取りしたい位置とかがくるのでシークして読んで返す
this.MediaStream.Seek(position, System.IO.SeekOrigin.Begin);
var result = this.MediaStream.Read(buffer, offset, size);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.