我想用VLC播放https流

时间:2019-07-02 13:41:47

标签: c# wpf libvlc

我想使用vlc播放https流,以下代码正在运行     winForm,但我希望它将其转换为wpf。因此,问题在于我们如何将VlcControl绑定到窗口或用户控件。我已经尝试过使用WindowFormHost,但无法正常工作。

public Vlc.DotNet.Forms.VlcControl VLC;
public void StartStream_Click(object s, EventArgs ev)
{
    if (VLC.IsPlaying)
    {
        return;
    }
    VLC = new VlcControl();
    VLC.VlcLibDirectory = new DirectoryInfo(@""+Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
    Task.Factory.StartNew(() =>
    {
        // Using ACS API to get live streaming
        PlayingCameras = new ObservableCollection<VlcControl>();
        foreach (var cam in selectedServer.Cameras)
        {
            Uri streamUrl = new Uri(
                "https://"
                + selectedServer.Server.UserName + ":"
                + selectedServer.Server +
                "@"
                + selectedServer.Server.IPAddress +
                // camera=3576 is just an example it should be replaced with your cameraId 
                // quality is jsu an example it should be replaced
                "/Acs/Streaming/Video/Live/Mp4/?camera=" + cam.CameraId.Split('#')[0] + "&quality=high&audio=0");

            VLC.SetMedia(streamUrl);

            VLC.EncounteredError += (sender, e) =>
            {
                LogHelper.WriteException(e.ToString(), source: "Quanika");
                VLC.Stop();
            };

            VLC.Play();

            PlayingCameras.Add(VLC);



            RaisePropertyChanged("VLC");
        }
    });


}

代码中没有问题。我不知道如何显示流媒体 在xml中。我已经发布了相同的代码,但已在winform中实现,我希望将其转换为WPF。

<Grid>
    <!--<WindowsFormsHost x:Name="VLCWindow"/>-->

        <Grid.Background>
            <VisualBrush Stretch="Uniform">
                <VisualBrush.Visual>
                    <Image Source="{Binding VLC, UpdateSourceTrigger=PropertyChanged}" />

                </VisualBrush.Visual>
            </VisualBrush >
        </Grid.Background>


    </Grid>

0 个答案:

没有答案