peony3000

Gadgeteer_USB_Music_01

Oct 14th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. using Microsoft.SPOT;
  5.  
  6. using GT = Gadgeteer;
  7. using GTM = Gadgeteer.Modules;
  8. using Gadgeteer.Modules.GHIElectronics;
  9.  
  10. namespace Gadgeteer_USB_Music_01
  11. {
  12.     public partial class Program
  13.     {
  14.         void ProgramStarted()
  15.         {
  16.             music.MusicFinished += new Music.MusicFinishedPlayingEventHandler(music_MusicFinished);
  17.             sdCard.SDCardMounted += new SDCard.SDCardMountedEventHandler(sdCard_SDCardMounted);
  18.  
  19.             music.SetVolume(180);
  20.  
  21.             Debug.Print("Program started");
  22.         }
  23.  
  24.         void sdCard_SDCardMounted(SDCard sender, GT.StorageDevice SDCard)
  25.         {
  26.             Debug.Print("SDCard mounted");
  27.  
  28.             FileStream fileStream;
  29.             foreach (string file in SDCard.ListRootDirectoryFiles())
  30.             {
  31.                 // Open the FileStream
  32.                 fileStream = new FileStream(@"\SD\" + file, FileMode.Open);
  33.  
  34.                 // Play the FileStream
  35.                 music.Play(fileStream);
  36.                 Debug.Print("Playing \"" + file + "\"...");
  37.  
  38.                 // Wait until this song finished playing
  39.                 while (music.IsBusy)
  40.                     Thread.Sleep(10);
  41.             }
  42.         }
  43.  
  44.         void music_MusicFinished(Music sender)
  45.         {
  46.             // Program will crash when switching to the
  47.             // next song if we don't have this event handler
  48.  
  49.             Debug.Print("Finished playing this song");
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment