All pastes #736567 Raw Edit

M. Cheeks

public text v1 · immutable
·published 2007-10-14 17:36 UTC
rendered paste body
// /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
{
	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)
		{
				Console.WriteLine("Starting");
			    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]);
			
			    int i = 0;
			
			    foreach(FileInfo fi in rgFiles)
			    {
				      player.GetSounds()[i] = fi.FullName;
				      i++;
			    }
			 
			    player.SetProgram("/usr/bin/mplayer");
			    player.SetTimers(new int[] {10, 13});
			    Random RandString = new Random(); 
			
			    int songs = player.GetSounds().Length;
			    int nbTimers = player.GetTimers().Length; 
			
			    while(true){
				   string song = player.GetSounds()[RandString.Next(0, songs -1)];
				   int timer = player.GetTimers()[RandString.Next(0, nbTimers - 1)] * 1000;   
				   System.Threading.Thread.Sleep(timer);
				   player.Play(song);
			    }
			
			     
		}
	}
}