Beispiel #1
0
        /// <summary>
        /// Parses the windows media player database.
        /// </summary>
        private async void ParseWMPDatabase()
        {
            EnableControls = false;

            try
            {
                await Task.Run(() =>
                {
                    OnStatusUpdated("Parsing Windows Media Player library...");
                    using (WMP wmp = new WMP())
                    {
                        // todo: this can be better
                        var scrobbles   = wmp.GetMusicLibrary();
                        var scrobbleVMs = new List <MediaDBScrobbleViewModel>();
                        foreach (var scrobble in scrobbles)
                        {
                            var vm = new MediaDBScrobbleViewModel(scrobble);
                            vm.ToScrobbleChanged += ToScrobbleChanged;
                            scrobbleVMs.Add(vm);
                        }

                        ParsedScrobbles = new ObservableCollection <MediaDBScrobbleViewModel>(scrobbleVMs);
                    }
                    OnStatusUpdated("Successfully parsed Windows Media Player library");
                });
            }
            catch (Exception ex)
            {
                OnStatusUpdated("Fatal error while parsing Windows Media Player library. Error: " + ex.Message);
            }
            finally
            {
                EnableControls = true;
            }
        }
Beispiel #2
0
 /// <summary>
 /// This event handler allows to stop playing.
 /// </summary>
 /// <param name="sender">The source of an event</param>
 /// <param name="e">Instance containing the event data</param>
 public void btnStop_Click(object sender, EventArgs e)
 {
     BeginInvoke(new Action(() =>
     {
         WMP.close();
     }));
 }
Beispiel #3
0
        /// <summary>
        /// (Tray) -> Playback -> Stop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StopTrayItem_Click(object sender, EventArgs e)
        {
            WMP wmpStreamEngine = new WMP();

            wmpStreamEngine.ControlAudio(AudioControlEnum.Stop, MediaPlayer);

            TrayIcon.Text = "Traydio";
        }
Beispiel #4
0
        void TrayMenu_Click(object sender, EventArgs e)
        {
            var name = (sender as ToolStripMenuItem).Text;
            var url  = (sender as ToolStripMenuItem).ToolTipText;

            if (!String.IsNullOrEmpty(url))
            {
                var wmp = new WMP();
                wmp.StreamAudio(url, MediaPlayer);

                NowPlayingTrayItem.Text = name;
                TrayIcon.Text           = "Traydio: " + name;
            }
        }
        private void MusicList_Click(object sender, EventArgs e)
        {
            if (musicList.SelectedItem != null)
            {
                WMPLib.IWMPMedia media;
                media = WMP.newMedia(music.patchs[musicList.SelectedIndex]);

                metroScrollBarMusic.Value   = 1;
                metroScrollBarMusic.Minimum = 1;
                metroScrollBarMusic.Maximum = (int)media.duration;
                metroScrollBarMusic.Update();

                WMP.currentMedia = media;
                WMP.Ctlcontrols.play();
                timer1.Start();
            }
        }
Beispiel #6
0
        private void fMediaPlayer_FormClosing(object sender, FormClosingEventArgs e)
        {
            PauseMusic();
            MediaPlayer.SaveSettings();
            MediaPlayer.SaveCustomSettings();

            if (MediaPlayer.list.Any())
            {
                MediaPlayer.currentPosition = WMP.Ctlcontrols.currentPosition;
                MediaPlayer.SaveListSettings();
                MediaPlayer.SaveList();
            }

            WMP.close();
            // HOOK SPACE
            KeyboardHook.UnInstallHook();
            MouseHook.UnInstallHook();
        }
Beispiel #7
0
 private void AddInPlayListWMP(string music)
 {
     WMPLib.IWMPMedia media = WMP.newMedia(music); // создаем новую медиа, и добавляем её в список
     WMP.currentPlaylist.appendItem(media);
 }
Beispiel #8
0
        /// <summary>
        /// (Tray) -> Playback -> Play
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PlayTrayItem_Click(object sender, EventArgs e)
        {
            WMP wmpStreamEngine = new WMP();

            wmpStreamEngine.ControlAudio(AudioControlEnum.Play, MediaPlayer);
        }
    /// <summary>
    /// Parses the windows media player database.
    /// </summary>
    private async void ParseWMPDatabase()
    {
      EnableControls = false;

      await Task.Run(() =>
      {
        OnStatusUpdated("Parsing Windows Media Player library...");
        using (WMP wmp = new WMP())
        {
          // todo: this can be better
          var scrobbles = wmp.GetMusicLibrary();
          var scrobbleVMs = new List<MediaDBScrobbleViewModel>();
          foreach (var scrobble in scrobbles)
          {
            var vm = new MediaDBScrobbleViewModel(scrobble);
            vm.ToScrobbleChanged += ToScrobbleChanged;
            scrobbleVMs.Add(vm);
          }

          ParsedScrobbles = new ObservableCollection<MediaDBScrobbleViewModel>(scrobbleVMs);
        }
        OnStatusUpdated("Successfully parsed Windows Media Player library");
      });

      EnableControls = true;
    }
Beispiel #10
0
 public virtual bool isDisplayable(string filter, WMP.Model.MediaFilter type)
 {
     return ((bool)(_dict[type].DynamicInvoke(filter)));
 }
Beispiel #11
0
        private void Form1_Load(object sender, EventArgs e)
        {
            readconfig();
            thistitle = this.Text;
            WriteLog("Program Started");


            if (runBlaze == true)
            {
                MyzoneServer mz = new MyzoneServer();
                mz.StartServer();
            }


            if (!Directory.Exists(logdir))
            {
                Directory.CreateDirectory(logdir);
                WriteLog("Created Log Dir");
            }

            if (runMusic == true)
            {
                this.FormClosing += new FormClosingEventHandler(form_closing);
                htpb.Width        = 393;
                htpb.Height       = 10;
                htpb.MouseClick  += new MouseEventHandler(htpb_click);
                htpb.Location     = new Point(4, 210);
                htpb.MouseMove   += new MouseEventHandler(htpb_hover);

                WMP.ErrorEvent += new EventHandler(WMP_OnError);

                htpb.BringToFront();
                this.Controls.Add(htpb);
                try
                {
                    SetCurrentEffectPreset(4);
                    WMP.BeginInit();
                }
                catch (Exception ex)
                {
                    WriteLog(ex.ToString());
                }


                WMP.settings.volume  = 0;
                WMP.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);

                WMP.enableContextMenu = false;
                WMP.uiMode            = "none";
                try
                {
                    Thread nthread = new Thread(Tcpserver);
                    nthread.IsBackground = true;
                    nthread.Start();
                }catch (Exception ex)
                {
                    WriteLog("Cannot Start Music Web Server");
                }
            }
            else
            {
                WMP.Visible        = false;
                btnSkip.Visible    = false;
                skpTime.Visible    = false;
                wmpTimer.Enabled   = false;
                lblCurTime.Visible = false;
                if (runBlaze == true)
                {
                    this.Text = thistitle + " - Running Blaze Server Only";
                }
                else
                {
                    this.Text = thistitle + " - No Services Running";
                }
            }
        }
Beispiel #12
0
        private void Tcpclientmgr(TcpClient tcpc, int clientid, string clientname)
        {
            //adds 1 to the program clientcount once this has been established so sync is maintained.
            clientcount++;
            int myid = clientid;
            //tcrun is used on a per thread basis to determine if this individual thread should still run
            Boolean tcrun = true;



            int       cmdreadcnt = inccmds.Count();
            NewClient thisclient = new NewClient(myid, tcpc.Client.RemoteEndPoint.ToString());

            //add our id and remote endpoint to the clientlist
            clientlist.Add(thisclient);
            //add our id and name to the clientlist - this is the list we will use later for our friendly name

            //overwrites endpoint client identifier with our naming client that can be modified later
            if (clientname != "")
            {
                thisclient = new NewClient(myid, clientname);
            }

            //adds the client to the list
            clientnames.Add(thisclient);


            byte[] nbuff = Encoding.ASCII.GetBytes("Client Connected:" + myid + vbcrlf + "To Send Shared Server Messages Use Chat:<Message>" + vbcrlf);
            //tcpc.Client.Send(nbuff);
            tcpc.ReceiveTimeout = 10;
            tcpc.SendTimeout    = 10;
            //servrun is main boolean to determine if whole program should execute
            //tcrun is the boolean to determine if each individual threaded tcpclient should run or not

            //sends data to tcpclient on each cycle of the while loop to determine if it is still open, if not it closes so as not to hog threads.
            try
            {
                byte[] tempbuff = new byte[1];
                //peek must be used so that we dont tie up the main receive buffer
                if (tcpc.Client.Receive(tempbuff, SocketFlags.Peek) < 1)
                {
                    tcpc.Close();
                    tcpc.Client.Close();
                    tcrun = false;
                    Thread.CurrentThread.Abort();
                }
            }
            catch (Exception excnct)
            {
                //WriteLog("TCP Server Error: " + excnct.ToString());
            }
            try
            {
                //this.Invoke(new Action(() => this.Text = string.Format("Hutchison Technologies - Fiit Manager {0}", pollcount) + " - " + cmdreadcnt + "-" + inccmds.Count()));
                //open network stream from tcp client
                NetworkStream ns = tcpc.GetStream();
                // must set timeouts so that thread does not hang on read
                ns.ReadTimeout  = 10;
                ns.WriteTimeout = 10;

                byte[] buffer = new byte[1024];

                String unencbuff = null;


                //makes sure data is available in the network stream before trying to read
                if (ns.DataAvailable == true)
                {
                    //makes sure reading is possible before trying to read
                    if (ns.CanRead == true)
                    {
                        // reads buffer value to byte
                        ns.Read(buffer, 0, 1024);

                        //steps through each byte in the byte array to make sure no dead data is held in memory if byte = 0 then it is not commited
                        foreach (byte b in buffer)
                        {
                            if (b != 0)
                            {
                                unencbuff += Convert.ToChar(b);
                            }
                        }

                        // writecmd(unencbuff);

                        try
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>");
                            sb.AppendLine("<root>");

                            string respbody = "<html><body><h1> Hello, Richard!</h1></body></html> ";
                            string response = "HTTP/1.1 200 OK\r\nDate: " + DateTime.Now.ToString("ddd MMM yyy HH:mm:SS") + "\r\nServer: Graeme Hind / 1.0 (Win64)\r\nLast - Modified: " + DateTime.Now.ToString("ddd MMM yyy HH:mm:SS") + "\r\nContent - Length: " + respbody.Length + "\r\nContent - Type: text / xml\r\nConnection: Closed";

                            //tries to split the incoming commands, this stops us having to user .compare and creates a more specific environment where we can specify command[1] = a result
                            String[] command = new string[2];

                            command = unencbuff.Split(Convert.ToChar(":"));



                            string[] responselines;
                            string[] separators = { "\r\n" };

                            responselines = unencbuff.Split(separators, StringSplitOptions.None);


                            string searchline = "GET /requests/status.xml";
                            string actcmd     = "";
                            string input      = "";
                            try
                            {
                                string cururl = "http://127.0.0.1:8080" + responselines[0].Replace("GET ", "").Replace("HTTP/1.1", "");

                                Uri nuri = new Uri(cururl);
                                actcmd = HttpUtility.ParseQueryString(nuri.Query).Get("command");
                                input  = HttpUtility.ParseQueryString(nuri.Query).Get("input");
                            }
                            catch (Exception ex)
                            {
                            }



                            try
                            {
                                if (actcmd.ToLower() == "in_play")
                                {
                                    input = HttpUtility.UrlDecode(input);

                                    WMP.URL = HttpUtility.HtmlDecode(input);


                                    Thread.Sleep(200);

                                    if (WMP.playState.ToString() == "wmppsPlaying")
                                    {
                                        skpTime.Maximum = Convert.ToInt32(WMP.currentMedia.duration);
                                        skpTime.Minimum = 0;
                                        skpTime.Enabled = true;
                                        btnSkip.Enabled = true;
                                        this.Invoke(new Action(() => this.Text = thistitle + " - Playing:" + WMP.currentMedia.name));
                                        Thread ntrd = new Thread(() => MusicFade("play"));
                                        ntrd.IsBackground = true;
                                        ntrd.Start();
                                    }
                                }
                                else if (actcmd.ToLower() == "pl_stop")
                                {
                                    //Thread ntrd = new Thread(() => MusicFade("stop"));
                                    //ntrd.IsBackground = true;
                                    //ntrd.Start();
                                    WMP.Invoke(new Action(() => WMP.Ctlcontrols.stop()));
                                }
                                else if (actcmd.ToLower() == "pl_empty")
                                {
                                    // Thread ntrd = new Thread(() => MusicFade("stop"));
                                    //ntrd.IsBackground = true;
                                    //ntrd.Start();

                                    WMP.Invoke(new Action(() => WMP.Ctlcontrols.stop()));
                                    WMP.Invoke(new Action(() => WMP.URL = ""));
                                }
                                else if (actcmd.ToLower() == "pause")
                                {
                                    //Thread ntrd = new Thread(()=> MusicFade("pause"));
                                    //ntrd.IsBackground = true;
                                    //ntrd.Start();
                                    WMP.Invoke(new Action(() => WMP.Ctlcontrols.pause()));
                                }
                                else if (actcmd.ToLower() == "play")
                                {
                                    Thread ntrd = new Thread(() => MusicFade("play"));
                                    ntrd.IsBackground = true;
                                    ntrd.Start();
                                }
                                else if (actcmd.ToLower() == "loop")
                                {
                                    if (input == "1")
                                    {
                                        WMP.settings.setMode("loop", true);
                                    }
                                    else if (input == "0")
                                    {
                                        WMP.settings.setMode("loop", false);
                                    }
                                }
                            }catch (Exception ex)
                            {
                            }


                            try
                            {
                                sb.AppendLine("<length>" + Convert.ToInt32(WMP.currentMedia.duration) + "</length>");
                            }catch (Exception ex)
                            {
                                sb.AppendLine("<length>0</length>");
                            }

                            sb.AppendLine("<time>" + Convert.ToInt32(WMP.Ctlcontrols.currentPosition) + "</time>");

                            if (WMP.playState.ToString() == "wmppsUndefined")
                            {
                                sb.AppendLine("<state>stopped</state>");
                            }
                            else if (WMP.playState.ToString() == "wmppsPlaying")
                            {
                                sb.AppendLine("<state>playing</state>");
                            }
                            else if (WMP.playState.ToString() == "wmppsStopped")
                            {
                                sb.AppendLine("<state>stopped</state>");
                            }
                            else
                            {
                                sb.AppendLine("<state>stopped</state>");
                            }
                            try
                            {
                                sb.AppendLine("<track>" + WMP.currentMedia.name + "</track>");
                            }  catch (Exception ex)
                            {
                            }
                            sb.AppendLine("</root>");
                            byte[] nbuffinc = Encoding.ASCII.GetBytes(response + "\r\n\r\n" + sb.ToString());
                            ns.Write(nbuffinc, 0, nbuffinc.Length);
                        }
                        catch (Exception ex)
                        {
                            // MessageBox.Show(ex.ToString());
                        }
                    }
                }

                try
                {
                    // for loop to cycle through all messages sitting in our list of messages which we earlier removed dead bytes from and commited

                    /*  for (int i = cmdreadcnt; i < inccmds.Count; i++)
                     * {
                     *    byte[] nbuffinc = Encoding.ASCII.GetBytes(inccmds[i]);
                     *
                     *    //keeps the regional variable in sync
                     *    cmdreadcnt++;
                     *
                     *    //write messages from the previous messages buffer to the connected client
                     *    if (ns.CanWrite == true)
                     *    {
                     *        ns.Write(nbuffinc, 0, nbuffinc.Length);
                     *
                     *    }
                     * }
                     * // ns.Write()
                     */
                }
                catch (Exception ex)
                {
                    WriteLog("TCP Client Manager: " + ex.ToString());
                }
            }
            catch (Exception mainex)
            {
                WriteLog("TCP Client Manager:" + mainex.ToString());
            }
            //sleep the thread for 1ms so it does not hog resources
            Thread.Sleep(1);



            //if exited from the while loop close the tcp client and abort the thread
            tcpc.Close();
            Thread.CurrentThread.Abort();
        }