Virtu/Virtu/Silverlight/Services/SilverlightAudioService.cs
Sean Fausett 2167383a00 Upgraded to Windows Phone 7 Beta.
Upgraded to FxCop 10.0.
Dropped Silverlight Toolkit dependency (for now).
Modified AudioService to avoid deadlocks by using timeouts.
Refactored DebugService and implementations.
Modified SilverlightVideoService to handle browser zoom.
Split Wpf MainWindow into MainPage child control.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4048619
2010-07-16 09:36:41 +00:00

61 lines
1.7 KiB
C#

using System;
using System.Windows.Controls;
using Jellyfish.Library;
namespace Jellyfish.Virtu.Services
{
public sealed class SilverlightAudioService : AudioService
{
public SilverlightAudioService(Machine machine, UserControl page, MediaElement media) :
base(machine)
{
if (page == null)
{
throw new ArgumentNullException("page");
}
if (media == null)
{
throw new ArgumentNullException("media");
}
_media = media;
_mediaSource = new WaveMediaStreamSource(SampleRate, SampleChannels, SampleBits, SampleSize, SampleLatency, OnMediaSourceUpdate);
_media.SetSource(_mediaSource);
page.Loaded += (sender, e) => _media.Play();
#if !WINDOWS_PHONE
page.Unloaded += (sender, e) => _media.Stop();
#endif
}
public override void SetVolume(double volume) // machine thread
{
_media.Dispatcher.BeginInvoke(() => _media.Volume = volume);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_mediaSource.Dispose();
}
base.Dispose(disposing);
}
private void OnMediaSourceUpdate(byte[] buffer, int bufferSize) // audio thread
{
//if (_count++ % (1000 / SampleLatency) == 0)
//{
// DebugService.WriteLine("OnMediaSourceUpdate");
//}
Update(bufferSize, (source, count) => Buffer.BlockCopy(source, 0, buffer, 0, count));
}
private MediaElement _media;
private WaveMediaStreamSource _mediaSource;
//private int _count;
}
}