本文整理汇总了C#中NAudio.Wave.WaveOut.Pause方法的典型用法代码示例。如果您正苦于以下问题:C# WaveOut.Pause方法的具体用法?C# WaveOut.Pause怎么用?C# WaveOut.Pause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.WaveOut
的用法示例。
在下文中一共展示了WaveOut.Pause方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
internal static void Main(string[] args)
{
// Create a SID reader.
sid = new SidReader("Tests/2short1s.sid", 44100, 2, SidModel.MOS8580, SidClock.NTSC);
// Initialize the player and start.
IWavePlayer player = new WaveOut();
player.Init(sid);
// Initialize track count
track = sid.CurrentSong;
// Display the initial track information.
DisplayTrackInfo();
// Loop to check if the user hits left or right arrow keys to change tracks.
ConsoleKeyInfo keyInfo;
do
{
keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.LeftArrow)
{
if (track > 1)
{
track--;
sid.SetTune(track);
DisplayTrackInfo();
}
}
else if (keyInfo.Key == ConsoleKey.RightArrow)
{
if (track != sid.NumberOfSubtunes)
{
track++;
sid.SetTune(track);
DisplayTrackInfo();
}
}
else if (keyInfo.Key == ConsoleKey.Spacebar)
{
if (isPlaying)
{
player.Pause();
isPlaying = false;
}
else
{
player.Play();
isPlaying = true;
}
}
} while (keyInfo.Key != ConsoleKey.Escape && keyInfo.Key != ConsoleKey.Enter);
}
示例2: Main
private static void Main(string[] args)
{
// Initialization
Console.OutputEncoding = Encoding.UTF8;
var ape = new ApeReader(args[0]);
DisplayInformation(ape.Handle);
// Set up the player.
IWavePlayer player = new WaveOut();
player.Init(ape);
player.Play();
// Listen for key presses to pause/play audio.
var isPlaying = true;
do
{
var keyInfo = Console.ReadKey();
if (keyInfo.Key == ConsoleKey.Spacebar)
{
if (isPlaying)
{
player.Pause();
isPlaying = false;
}
else
{
player.Play();
isPlaying = true;
}
}
// If we hit the end of the stream in terms of actual audio data.
if (isPlaying && ape.Position == ape.Length)
{
player.Stop();
}
} while (player.PlaybackState != PlaybackState.Stopped);
}
示例3: StartPlayingThisClip
private void StartPlayingThisClip(AudioClipToPlay clip, double curSec)
{
cxzxc(string.Format("start of {0} {1}-{2}", clip.Filename, clip.SecFileStart, clip.SecFileEnd));
// create the device
IWavePlayer waveOutDevice = new WaveOut();
var deviceAndShit = new DeviceAndItsData(waveOutDevice, clip);
lock (this) { devicesPlaying.Add(deviceAndShit); }
Thread ttt = new Thread(() =>
{
using (var reader = OpenAudioFile(clip.Filename))
{
deviceAndShit.WaveReader = reader;
// init the playback stuff
waveOutDevice.Init(reader);
var syncOffsetSec = curSec - clip.SecOffset; // would be 0 if curSec == clip.SecOffset
var clipSecStart = clip.SecFileStart + syncOffsetSec;
var clipSecEnd = clip.SecFileEnd;
reader.CurrentTime = TimeSpan.FromSeconds(clipSecStart + NAUDIO_SYNC_OFFSET);
var endTs = TimeSpan.FromSeconds(clipSecEnd + NAUDIO_SYNC_OFFSET);
var sleepTs = TimeSpan.FromSeconds(NAUDIO_SLEEP_FRAME_TIME);
deviceAndShit.PlaybackStateRequest = PlaybackState.Playing;
waveOutDevice.Play();
while (reader.CurrentTime < endTs)
{
Thread.Sleep(sleepTs);
if (waveOutDevice.PlaybackState == PlaybackState.Playing && deviceAndShit.PlaybackStateRequest == PlaybackState.Paused)
waveOutDevice.Pause();
if (waveOutDevice.PlaybackState == PlaybackState.Paused && deviceAndShit.PlaybackStateRequest == PlaybackState.Playing)
waveOutDevice.Play();
if (deviceAndShit.StopHasBeenInvoked)
break;
if (waveOutDevice.PlaybackState == PlaybackState.Stopped)
break;
}
waveOutDevice.Stop(); // no harm calling stop 2x right?
lock (this) {
devicesPlaying.Remove(deviceAndShit);
devicesPaused.Remove(deviceAndShit);
}
cxzxc(string.Format("stop of {0} {1}-{2}", clip.Filename, clip.SecFileStart, clip.SecFileEnd));
}
});
ttt.Start();
}