Пример #1
0
        public FormPlayer(IntPtr handle, int dpi, int volume, string url, string token)
        {
            InitializeComponent();

            this.ownerHandle  = handle;
            this.ownerDpi     = dpi / 100F;
            this.videoUrl     = url;
            this.pipe         = DuplexPipe.CreateClient(token);
            this.pipe.DataIn += pipe_DataIn;

            if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect))
            {
                ClientSize = new Size(0, 0);
                Location   = new Point((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2);
                Opacity    = 0;
            }

            player = new ControlWMP {
                Dock = DockStyle.Fill
            };

            player.BeginInit();
            Controls.Add(player);
            player.EndInit();

            Player.enableContextMenu           = false;
            Player.uiMode                      = "none";
            Player.settings.autoStart          = false;
            Player.settings.enableErrorDialogs = false;
            Player.settings.setMode("loop", true);

            Player.PlayStateChange += player_PlayStateChange;
            Player.PositionChange  += player_PositionChange;
            Player.MediaError      += player_MediaError;

            trackBarVolume.Value = volume;             // changes player volume too if non-default

            labelTooltip.AttachTooltip(progressSeek, true, args => {
                if (args.X < 0 || args.Y < 0 || args.X >= progressSeek.Width || args.Y >= progressSeek.Height)
                {
                    return(null);
                }

                IWMPMedia media = Player.currentMedia;
                int progress    = (int)(media.duration * progressSeek.GetProgress(args.X));

                Marshal.ReleaseComObject(media);

                return($"{(progress / 60):00}:{(progress % 60):00}");
            });

            labelTooltip.AttachTooltip(trackBarVolume, false, args => $"Volume : {trackBarVolume.Value}%");

            labelTooltip.AttachTooltip(imageClose, false, "Close");
            labelTooltip.AttachTooltip(imageDownload, false, "Download");
            labelTooltip.AttachTooltip(imageResize, false, "Fullscreen");

            Application.AddMessageFilter(new MessageFilter(this));
        }
Пример #2
0
        public SoundPlayerImplWMP()
        {
            owner = new Form();
            wmp   = new ControlWMP();
            wmp.BeginInit();
            owner.Controls.Add(wmp);
            wmp.EndInit();

            Player.uiMode                      = "none";
            Player.settings.autoStart          = false;
            Player.settings.enableErrorDialogs = false;
            Player.settings.invokeURLs         = false;
            Player.settings.volume             = 0;
            Player.MediaChange                += player_MediaChange;
            Player.MediaError                 += player_MediaError;
        }
Пример #3
0
        public FormPlayer(IntPtr handle, int volume, string url, string token)
        {
            InitializeComponent();

            this.ownerHandle  = handle;
            this.videoUrl     = url;
            this.pipe         = DuplexPipe.CreateClient(token);
            this.pipe.DataIn += pipe_DataIn;

            player = new ControlWMP {
                Dock = DockStyle.Fill
            };

            player.BeginInit();
            Controls.Add(player);
            player.EndInit();

            Player.enableContextMenu           = false;
            Player.uiMode                      = "none";
            Player.settings.autoStart          = false;
            Player.settings.enableErrorDialogs = false;
            Player.settings.setMode("loop", true);

            Player.PlayStateChange += player_PlayStateChange;
            Player.MediaError      += player_MediaError;

            trackBarVolume.Value = volume; // changes player volume too if non-default

            labelTooltip.AttachTooltip(progressSeek, true, args => {
                IWMPMedia media = Player.currentMedia;
                int progress    = (int)(media.duration * progressSeek.GetProgress(args.X));

                Marshal.ReleaseComObject(media);

                return($"{(progress/60).ToString("00")}:{(progress%60).ToString("00")}");
            });

            labelTooltip.AttachTooltip(trackBarVolume, false, args => $"Volume : {trackBarVolume.Value}%");

            labelTooltip.AttachTooltip(imageClose, false, "Close");
            labelTooltip.AttachTooltip(imageDownload, false, "Download");
            labelTooltip.AttachTooltip(imageResize, false, "Fullscreen");

            Application.AddMessageFilter(new MessageFilter(this));
        }