Ejemplo n.º 1
0
        public frmUNIcastPlayer()
        {
            InitializeComponent();

            // Load settings
            IniFile ini = new IniFile(Path.Combine(Environment.CurrentDirectory, IniFile));
            string  str = ini.IniReadValue(Section, KeyStream);

            if (!Address.TryParse(str, out streamAddress))
            {
                streamAddress = DefaultStreamAddress;
                ini.IniWriteValue(Section, KeyStream, streamAddress.ToString());
            }
            str = ini.IniReadValue(Section, KeyMessage);
            if (!Address.TryParse(str, out messageAddress))
            {
                messageAddress = DefaultMessageAddress;
                ini.IniWriteValue(Section, KeyMessage, messageAddress.ToString());
            }
            str = ini.IniReadValue(Section, KeyHWA);
            if (!Boolean.TryParse(str, out enableHWA))
            {
                enableHWA = DefaultHWA;
                ini.IniWriteValue(Section, KeyHWA, enableHWA.ToString());
            }

            Debug.WriteLine("streamAddress: " + streamAddress);
            Debug.WriteLine("messageAddress: " + messageAddress);
            Debug.WriteLine("HWA: " + enableHWA);

            // Last supported VLC version: VLC 2.0.8 "Twoflower"
            string[] args = new string[] {
                "-I", "dummy", "--ignore-config",

                // don't display file path
                "--no-video-title-show",

                // keep showing logo
                // http://stackoverflow.com/questions/15992874/logo-appears-for-only-a-second-and-then-disappears
                "--sub-filter=logo",

                // Caching value for network resources, in milliseconds.
                "--network-caching=60",

                // C:\Program Files (x86)\VideoLAN\VLC\plugins"
                @"--plugin-path=VLC_PLUGIN_PATH"
            };

            // Enable hardware acceleration based on settings
            if (enableHWA)
            {
                List <string> argsList = args.ToList();
                argsList.Add("--ffmpeg-hw");
                args = argsList.ToArray();
            }
            else
            {
                ibtnHWA.Visible = false;
            }

            instance = new VlcInstance(args);
            player   = null;

            cropMode = CropMode.NoCropping;

            margin = this.Width - ucVLC.Width;

            this.MinimumSize = DefaultClientSize;

            Debug.WriteLine(LibVlc.GetLibVlcVersion());

            media  = new VlcMedia(instance, String.Format("udp://@{0}", streamAddress));
            player = new VlcMediaPlayer(media);

            stoppedDelegate = new LibVlc.EventCallbackDelegate(MediaPlayerStopped);
            playingDelegate = new LibVlc.EventCallbackDelegate(MediaPlayerPlaying);

            player.EventAttach(LibVlc.libvlc_event_e.libvlc_MediaStateChanged, stoppedDelegate);
            player.EventAttach(LibVlc.libvlc_event_e.libvlc_MediaPlayerStopped, stoppedDelegate);
            player.EventAttach(LibVlc.libvlc_event_e.libvlc_MediaPlayerPlaying, playingDelegate);

            player.Drawable = ucVLC.Handle;
            //ucVLC.BringToFront();
            player.Play();

            multicastClient = new MulticastClient(messageAddress.IP, messageAddress.Port);
            multicastClient.OnInputPositionReceived += multicastClient_OnInputPositionReceived;
            multicastClient.BeginReceive();
        }