peony3000

Gadgeteer mp3 player (needs extra using)

Apr 3rd, 2012
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. using System.Threading;
  2. using Microsoft.SPOT;
  3.  
  4. using GT = Gadgeteer;
  5. using GTM = Gadgeteer.Modules;
  6. using Gadgeteer.Modules.GHIElectronics;
  7.  
  8. using System.IO;
  9. using System.Net;
  10.  
  11. namespace Gadgeteer_Music_01
  12. {
  13.     public partial class Program
  14.     {
  15.         string musicFile;
  16.         GT.StorageDevice usbStorage;
  17.  
  18.         void ProgramStarted()
  19.         {
  20.             // Initialize event handling robots
  21.             usbHost.USBDriveConnected += new GTM.GHIElectronics.UsbHost.USBDriveConnectedEventHandler(usb_USBDriveConnected);
  22.             usbHost.USBDriveDisconnected += new GTM.GHIElectronics.UsbHost.USBDriveDisconnectedEventHandler(usb_USBDriveDisconnected);
  23.            
  24.             // button press watching robot
  25.             button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
  26.            
  27.             // music finished listening robot
  28.             music.MusicFinished += new Music.MusicFinishedPlayingEventHandler(music_MusicFinished);
  29.            
  30.             // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
  31.             Debug.Print("Program Started");
  32.         }
  33.  
  34.         void music_MusicFinished(Music sender)
  35.         {
  36.             Debug.Print("music finished");
  37.         }
  38.  
  39.         void button_ButtonPressed(Button sender, Button.ButtonState state)
  40.         {
  41.            
  42.             FileStream stream = usbStorage.Open(musicFile, FileMode.Open, FileAccess.Read);
  43.             music.SetVolume(255);    
  44.             music.Play(stream);
  45.            
  46.  
  47.                 //while (music.IsBusy)  // You can't call music.StopPlaying or set volume with this loop running.
  48.                     //Thread.Sleep(10);
  49.             /*
  50.                 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://integral-data.com/NewYorkNewYork_32kbs.wma");
  51.                 music.SetVolume(200);
  52.                 music.Play(httpWebRequest.GetResponse().GetResponseStream());
  53.                 while (music.IsBusy)
  54.                     Thread.Sleep(10);
  55.                 httpWebRequest.Dispose();
  56.             */
  57.         }
  58.             void usb_USBDriveDisconnected(GTM.GHIElectronics.UsbHost sender)
  59.         {
  60.             Debug.Print("\r\nThe USB thumb drive has been removed.");
  61.         }
  62.  
  63.         void usb_USBDriveConnected(GTM.GHIElectronics.UsbHost sender, GT.StorageDevice storageDevice)
  64.         {
  65.             Debug.Print("\r\nUSB thumb drive has been inserted.");
  66.             Debug.Print("Using storageDevice from the USBDriveConnected event, the root director is:");
  67.             string[] root = storageDevice.ListRootDirectoryFiles();
  68.             foreach (string fileName in root)
  69.             {
  70.                 Debug.Print("    " + fileName);
  71.             }
  72.             Debug.Print("\r\nPlease remove the USB thumb drive to continue");
  73.  
  74.             musicFile = "Public Enemy - Rebel Without A Pause (1989).mp3";
  75.             usbStorage = storageDevice;
  76.         }
  77.  
  78.        
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment