Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Threading;
- using Microsoft.SPOT;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- using System.IO;
- using System.Net;
- namespace Gadgeteer_Music_01
- {
- public partial class Program
- {
- string musicFile;
- GT.StorageDevice usbStorage;
- void ProgramStarted()
- {
- // Initialize event handling robots
- usbHost.USBDriveConnected += new GTM.GHIElectronics.UsbHost.USBDriveConnectedEventHandler(usb_USBDriveConnected);
- usbHost.USBDriveDisconnected += new GTM.GHIElectronics.UsbHost.USBDriveDisconnectedEventHandler(usb_USBDriveDisconnected);
- // button press watching robot
- button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
- // music finished listening robot
- music.MusicFinished += new Music.MusicFinishedPlayingEventHandler(music_MusicFinished);
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void music_MusicFinished(Music sender)
- {
- Debug.Print("music finished");
- }
- void button_ButtonPressed(Button sender, Button.ButtonState state)
- {
- FileStream stream = usbStorage.Open(musicFile, FileMode.Open, FileAccess.Read);
- music.SetVolume(255);
- music.Play(stream);
- //while (music.IsBusy) // You can't call music.StopPlaying or set volume with this loop running.
- //Thread.Sleep(10);
- /*
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://integral-data.com/NewYorkNewYork_32kbs.wma");
- music.SetVolume(200);
- music.Play(httpWebRequest.GetResponse().GetResponseStream());
- while (music.IsBusy)
- Thread.Sleep(10);
- httpWebRequest.Dispose();
- */
- }
- void usb_USBDriveDisconnected(GTM.GHIElectronics.UsbHost sender)
- {
- Debug.Print("\r\nThe USB thumb drive has been removed.");
- }
- void usb_USBDriveConnected(GTM.GHIElectronics.UsbHost sender, GT.StorageDevice storageDevice)
- {
- Debug.Print("\r\nUSB thumb drive has been inserted.");
- Debug.Print("Using storageDevice from the USBDriveConnected event, the root director is:");
- string[] root = storageDevice.ListRootDirectoryFiles();
- foreach (string fileName in root)
- {
- Debug.Print(" " + fileName);
- }
- Debug.Print("\r\nPlease remove the USB thumb drive to continue");
- musicFile = "Public Enemy - Rebel Without A Pause (1989).mp3";
- usbStorage = storageDevice;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment