0

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!

Sergey
  • 1
  • have you checked to see if it uses the same encoding as other streams that work? Is that encoding supported? – Jason Apr 30 '22 at 17:52
  • I don't know how to check it. but as far as I know the encoding should be supported. – Sergey May 01 '22 at 07:43
  • there are hundreds if not thousands of readily available video tools that will tell you what encoding is being used – Jason May 01 '22 at 12:54

2 Answers2

0

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)
cube45
  • 3,429
  • 2
  • 24
  • 35
  • but why other streams work fine - https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8 – Sergey May 01 '22 at 08:32
  • It shouldn't. Please create a minimal reproducible sample for your "working" situation. Either it doesn't work, or there's an issue with Dispose() that doesn't destroy the player. – cube45 May 01 '22 at 12:21
  • I'm sorry, here is the code that works with this stream - private void PlayVideo(string url) { Core.Initialize(); _libVLC = new LibVLC(); mediaPlayer = new MediaPlayer(_libVLC) { EnableHardwareDecoding = true }; videoView.MediaPlayer = mediaPlayer; media = new Media(_libVLC, url, FromType.FromLocation); media.Parse(MediaParseOptions.ParseNetwork); mediaPlayer.Media = media; mediaPlayer.Play(); } – Sergey May 01 '22 at 12:54
  • Then you solved your issue, what's wrong then? – cube45 May 01 '22 at 16:03
  • this code does not work with the stream - https://s1.moidom-stream.ru/s/public/0000000088.m3u8 – Sergey May 01 '22 at 16:30
  • Then edit your question to include logs. Does it work with VLC for Android? (The official app) – cube45 May 01 '22 at 20:18
0

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();
mfkl
  • 1,914
  • 1
  • 11
  • 21
  • Only for m3u8 that represents a playlist of different media. If that's a single HLS stream, just calling Play() works. I admit I didn't have a look at the playlist type. – cube45 May 02 '22 at 04:24
  • This code works fine, but only on windows. – Sergey May 02 '22 at 07:17