Ejemplo n.º 1
0
        /// <summary>
        /// This method adds a track to the playlist.
        /// </summary>
        /// <param name="path">The path to the song.</param>
        /// <param name="macID">The link that added the song.</param>
        public static void AddTrack(string path, string macID)
        {
            int pos = playlist.Enqueue(path, macID);

            waitHandle.Set();
            Debug.Print("Received track \"" + path + "\" from " + macID);
            WT32.BroadcastMessage("QUEUE#" + pos + "|" + path);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The main thread method that plays the music.
        /// </summary>
        private static void PlayMusic()
        {
            byte[]     buffer = new byte[2048];
            int        size;
            FileStream file;

            while (true)
            {
                if (playlist.Count <= 0)
                {
                    waitHandle.WaitOne();
                }
                waitHandle.Reset();
                // Get next song from queue
                string song = playlist.Dequeue();
                currentTrackPath = song;
                // Notify connected phones of new song
                WT32.BroadcastMessage("REMOVE#0");
                WT32.BroadcastMessage("PLAYING#" + song);
                Debug.Print("BlueConePlayer: Playing \"" + song + "\"");
                LED.State = LEDState.Playing;
                file      = File.OpenRead(song);
                bool DPSSent = false;
                do
                {
                    if (cancelPlayback)
                    {
                        VS1053.CancelPlayback();
                        size = file.Read(buffer, 0, buffer.Length);
                        VS1053.SendData(buffer);
                        break;
                    }
                    else
                    {
                        size = file.Read(buffer, 0, buffer.Length);
                        VS1053.SendData(buffer);
                        int decodeTime = VS1053.GetDecodeTime();
                        if (decodeTime >= 10 && !DPSSent)
                        {
                            int    byteRate    = VS1053.GetByteRate();
                            double playPercent = ((double)((double)(decodeTime * byteRate) / file.Length) * 100);
                            if (playPercent > 1)
                            {
                                WT32.BroadcastMessage("DECODE#" + decodeTime + "|" + playPercent);
                                DPSSent = true;
                            }
                        }
                    }
                } while (size > 0);
                // Song finished playing
                VS1053.Reset();
                currentTrackPath = null;
                file.Close();
                file.Dispose();
                LED.State = LEDState.Ready;
            }
        }
Ejemplo n.º 3
0
        private static void BlueConeMessageReceived(BluetoothMessage message)
        {
            tmp = message.Command.Split('#');
            switch (tmp[0].Trim())
            {
            case "NEXT":
                BlueConePlayer.Next();
                break;

            case "PLAY":
                Debug.Print("PLAY");
                break;

            case "PAUSE":
                Debug.Print("PAUSE");
                break;

            case "STOP":
                Debug.Print("STOP");
                break;

            case "PRI":
                Debug.Print("PRI");
                Debug.Print(tmp[1].Trim());
                if (tmp[1].Trim() == "0")
                {
                    BlueConePlayer.UsePriority(false);
                }
                else
                {
                    BlueConePlayer.UsePriority(true);
                }
                break;

            case "ADD":     // ADD#PATH
                BlueConePlayer.AddTrack(tmp[1].Trim(), ((Connection)WT32.Connections[message.Link]).Address);
                break;

            case "VOLUP":
                VS1053.VolUp();
                break;

            case "VOLDOWN":
                VS1053.VolDown();
                break;

            case "MASTER":
                if (tmp[1].Trim() == Settings.MasterPassword)
                {
                    WT32.SendMessage(new BluetoothMessage(message.Link, "MASTER#OK|" + BlueConePlayer.PriorityOn.ToString()));
                }
                else
                {
                    WT32.SendMessage(new BluetoothMessage(message.Link, "MASTER#ERR"));
                }
                break;

            case "QUEUEREMOVE":
                int i = BlueConePlayer.RemoveTrack(tmp[1].Trim());
                WT32.BroadcastMessage("REMOVE#" + i);
                Debug.Print("QueueRemove: " + tmp[1].Trim());
                break;

            case "REQ_QUEUE":
                BlueConePlayer.SendTracks((Connection)WT32.Connections[message.Link], false);
                break;

            case "REQ_ALL":
                BlueConePlayer.SendTracks((Connection)WT32.Connections[message.Link], true);
                break;

            default:
                Debug.Print(message.Command + ", Link: " + message.Link);
                break;
            }
            message.Dispose();
        }