I'm trying to play the video stream "https://s2.moidom-stream.ru/s/public/0000000087.m3u8" using LibVlc, but I only get a black screen. Other threads work fine, but I need this particular thread.
code used:
using Android.App;
using Android.OS;
using Android.Widget;
using LibVLCSharp.Shared;
using System;
using System.Linq;
using WebCamTst.Helpers;
namespace WebCamTst
{
[Activity(Label = "PanelActivity")]
public class PanelActivity : Activity
{
LibVLCSharp.Platforms.Android.VideoView videoView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.videopanel);
videoView = FindViewById<LibVLCSharp.Platforms.Android.VideoView>(Resource.Id.videoView1);
}
protected override void OnResume()
{
base.OnResume();
PlayVideo("https://s2.moidom-stream.ru/s/public/0000000087.m3u8");
}
private void PlayVideo(string url)
{
Core.Initialize();
using (var libVLC = new LibVLC())
using (var mPlayer = new MediaPlayer(libVLC) { EnableHardwareDecoding = true })
{
videoView.MediaPlayer = mPlayer;
var _media = new Media(libVLC, url, FromType.FromLocation);
_media.Parse(MediaParseOptions.ParseNetwork);
mPlayer.Play(_media);
}
}
}
}
but it doesn't work. Please help!
CodePudding user response:
Please start with one of the official android samples.
It doesn't work because Play() is not a synchronous method. It actually starts the libvlc thread in the background.
This means that your libvlc and your player are disposed too early and your video is stopped immediately.
Other remarks:
- You can Dispose() your media immediately after having passed into the media player.
- Your call to Parse is useless because it's also asynchronous and isn't required (Play calls it anyway)
CodePudding user response:
In addition to cube45's answer, m3u8 are played differently than regular media...
var libVLC = new LibVLC();
var media = new Media(libVLC, "https://s2.moidom-stream.ru/s/public/0000000087.m3u8", FromType.FromLocation);
await media.Parse(MediaParseOptions.ParseNetwork);
var mp = new MediaPlayer(media.SubItems.First());
mp.Play();