5 using System.Threading;
6 using SiliconStudio.Core.Serialization;
8 namespace SiliconStudio.
Paradox.Audio
31 #if SILICONSTUDIO_PLATFORM_ANDROID
32 internal readonly
string FileName;
33 internal readonly
long StartPosition;
34 internal readonly
long Length;
36 internal readonly MemoryStream
Stream;
57 throw new ArgumentNullException(
"engine");
60 throw new ArgumentNullException(
"stream");
63 throw new ObjectDisposedException(
"The AudioEngine in which to create the voice is disposed.");
69 ret.ResetStateToDefault();
70 ret.Name =
"SoundMusic " + soundMusicCreationCount;
72 engine.RegisterSound(ret);
74 Interlocked.Increment(ref soundMusicCreationCount);
82 private static int soundMusicCreationCount;
87 #if SILICONSTUDIO_PLATFORM_ANDROID
89 if (virtualStream == null)
90 throw new InvalidOperationException(
"Expecting VirtualFileStream. Music files needs to be stored on the virtual file system in a non-compressed form.");
92 var fileStream = virtualStream.InternalStream as FileStream;
93 if (fileStream == null)
94 throw new InvalidOperationException(
"Expecting FileStream in VirtualFileStream.InternalStream. Music files needs to be stored on the virtual file system in a non-compressed form.");
96 FileName = fileStream.Name;
97 StartPosition = virtualStream.StartPosition;
98 Length = virtualStream.Length;
101 var memoryStream =
new MemoryStream();
102 stream.CopyTo(memoryStream);
108 private void ResetStateToDefault()
115 private static SoundMusic previousPlayingInstance;
116 private static readonly
object PreviousPlayingInstanceLock =
new object();
118 internal override void PlayImpl()
120 AudioEngine.SubmitMusicActionRequest(
new SoundMusicActionRequest(
this, SoundMusicAction.Play));
126 lock (PreviousPlayingInstanceLock)
128 if (previousPlayingInstance !=
this)
130 if (previousPlayingInstance != null)
131 previousPlayingInstance.SetStateToStopped();
133 previousPlayingInstance =
this;
138 internal override void PauseImpl()
140 AudioEngine.SubmitMusicActionRequest(
new SoundMusicActionRequest(
this, SoundMusicAction.Pause));
143 internal override void StopImpl()
145 ShouldExitLoop =
false;
147 AudioEngine.SubmitMusicActionRequest(
new SoundMusicActionRequest(
this, SoundMusicAction.Stop));
150 internal override void UpdateVolume()
152 AudioEngine.SubmitMusicActionRequest(
new SoundMusicActionRequest(
this, SoundMusicAction.Volume));
155 internal override void UpdateLooping()
161 internal void SetStateToStopped()
163 PlayState = SoundPlayState.Stopped;
164 DataBufferLoaded =
false;
165 ShouldExitLoop =
false;
168 internal bool ShouldExitLoop {
get;
private set; }
170 internal override void ExitLoopImpl()
172 ShouldExitLoop =
true;
175 internal override void DestroyImpl()
177 AudioEngine.UnregisterSound(
this);
bool IsDisposed
Has the component been disposed or not yet.
Base class for sound that creates voices
Represents the audio engine. In current version, the audio engine necessarily creates its context on ...
This class provides a sound resource which is playable but not localizable.
static SoundMusic Load(AudioEngine engine, Stream stream)
Create and Load a sound music from an input file.
A multithreaded wrapper over a Stream, used by the VirtualFileSystem. It also allows restricted acces...