// /home/mrcheeks/Projects/Mono/neighbors/neighbors/Main.cs created with MonoDevelop
// User: mrcheeks at 3:19 P 13/10/2007
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
// project created on 13/10/2007 at 3:19 P
using System;
using System.Collections;
using System.IO;
using System.Diagnostics;
namespace neighbors
{
/// <summary>
/// A class to bother the neighbours, be sure to add nasty noises to a directory
/// exemples : cow.wav, gun.wav, laugh.wav, cough.wav, etc. :p, let the neighbors have fun...
/// </summary>
class SoundPlayer{
private string[] sounds;
private String program;
private int[] timers;
public SoundPlayer(){
}
public void Play(String song){
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = this.program;
p.StartInfo.Arguments = song;
p.Start();
p.WaitForExit();
}
public string[] GetSounds(){
return this.sounds;
}
public void SetSounds(string[] sounds){
this.sounds = sounds;
}
public void SetProgram(String program){
this.program = program;
}
public int[] GetTimers(){
return timers;
}
public void SetTimers(int[] timers){
this.timers = timers;
}
}
class MainClass
{
public static void Main(string[] args)
{
SoundPlayer player = new SoundPlayer();
ArrayList sounds = new ArrayList();
DirectoryInfo di = new DirectoryInfo("/home/mrcheeks/Sounds");
FileInfo[] rgFiles = di.GetFiles();
player.SetSounds( new string[rgFiles.Length] );
for(int i = 0; i<rgFiles.Length; i++){
player.GetSounds()[i] = rgFiles[i].FullName;
}
player.SetProgram("/usr/bin/mplayer");
player.SetTimers(new int[] {1600, 1800, 1500, 2000, 2100, 2300, 2400, 1900, 1700});
int songs = player.GetSounds().Length;
int nbTimers = player.GetTimers().Length;
while(true){
Random RandString = new Random();
string song = player.GetSounds()[RandString.Next(0, songs -1)];
int timer = player.GetTimers()[RandString.Next(0, nbTimers - 1)] * 1000;
DateTime CurrTime = DateTime.Now;
Console.WriteLine("Date = {0:R}", CurrTime );
Console.WriteLine("Next song in " + timer/1000/60 + " minutes");
System.Threading.Thread.Sleep(timer);
player.Play(song);
}
}
}
}