caudio/Samples/CSharpAudioPlayer/CSharpTutorial1_2DSound/Program.cs

67 lines
2.1 KiB
C#
Raw Normal View History

2011-06-26 01:24:25 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using cAudio;
namespace CSharpTutorial1_2DSound
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Some fancy text
Console.WriteLine("cAudio 2.2.0 Tutorial 1: Basic 2D Audio. C# \n \n");
Console.WriteLine("\nAvailable Playback Devices: \n");
2011-06-26 01:34:10 +02:00
//Grab a list of available devices
2011-06-26 01:24:25 +02:00
IAudioDeviceList pDeviceList = cAudioCSharpWrapper.createAudioDeviceList();
2011-06-26 01:34:10 +02:00
//Get the default device name.
string defaultDeviceName = pDeviceList.getDefaultDeviceName();
2011-06-26 01:24:25 +02:00
2011-06-26 01:34:10 +02:00
for(uint i=0; i< pDeviceList.getDeviceCount(); i++)
2011-06-26 01:24:25 +02:00
{
2011-06-26 01:34:10 +02:00
string deviceName = pDeviceList.getDeviceName(i);
2011-06-26 01:24:25 +02:00
if(deviceName.Equals(defaultDeviceName))
2011-06-26 01:34:10 +02:00
Console.WriteLine(" "+ i + "): " + deviceName + " [DEFAULT]");
2011-06-26 01:24:25 +02:00
else
2011-06-26 01:34:10 +02:00
Console.WriteLine(" "+ i + "): " + deviceName);
2011-06-26 01:24:25 +02:00
}
Console.WriteLine("\n");
Console.WriteLine("Choose a device by number: ");
string deviceSelection = Console.ReadLine();
uint deviceSelect = Convert.ToUInt32(deviceSelection);
Console.WriteLine("\n");
2011-06-26 01:34:10 +02:00
//Create an uninitialized Audio Manager
IAudioManager audioMgr = cAudioCSharpWrapper.createAudioManager(false);
audioMgr.initialize(pDeviceList.getDeviceName(deviceSelect));
2011-06-26 01:24:25 +02:00
2011-06-26 01:34:10 +02:00
IAudioSource currentSource = audioMgr.create("bing", "../../../Media/cAudioTheme1.ogg");
if (currentSource != null)
{
currentSource.setVolume(0.5f);
currentSource.play2d(false);
2011-06-26 01:24:25 +02:00
2011-06-26 01:34:10 +02:00
while (currentSource.isPlaying())
2011-06-26 01:24:25 +02:00
{
2011-06-26 01:34:10 +02:00
cAudioCSharpWrapper.cAudioSleep(10);
2011-06-26 01:24:25 +02:00
}
}
2011-06-26 01:34:10 +02:00
audioMgr.Dispose();
2011-06-26 01:24:25 +02:00
2011-06-26 01:34:10 +02:00
Console.WriteLine(@"Press any key to quit ");
2011-06-26 01:24:25 +02:00
Console.ReadLine();
}
}
}