-
Notifications
You must be signed in to change notification settings - Fork 33
/
SoundDevice.cs
68 lines (60 loc) · 1.66 KB
/
SoundDevice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using DeltaEngine.Core;
using DeltaEngine.Entities;
namespace DeltaEngine.Multimedia
{
/// <summary>
/// Holds the audio device and automatically disposes all finished playing sound instances.
/// </summary>
public abstract class SoundDevice : Entity, RapidUpdateable
{
public virtual void RapidUpdate()
{
if (currentPlayingMusic != null)
currentPlayingMusic.Run();
if (currentPlayingVideo != null)
currentPlayingVideo.Update();
}
private Music currentPlayingMusic;
private Video currentPlayingVideo;
public void RegisterCurrentMusic(Music music)
{
if (IsStopNeededForRegister(music, currentPlayingMusic))
currentPlayingMusic.Stop();
currentPlayingMusic = music;
}
private static bool IsStopNeededForRegister<T>(T newInstance, T currentInstance)
where T : class
{
return newInstance != null && currentInstance != null;
}
public void RegisterCurrentVideo(Video video)
{
if (IsStopNeededForRegister(video, currentPlayingVideo))
currentPlayingVideo.Stop();
currentPlayingVideo = video;
}
public override void Dispose()
{
if (currentPlayingMusic != null)
currentPlayingMusic.Dispose();
currentPlayingMusic = null;
if (currentPlayingVideo != null)
currentPlayingVideo.Dispose();
currentPlayingVideo = null;
}
public override bool IsPauseable
{
get { return false; }
}
public float MusicVolume
{
get { return Settings.Current.MusicVolume; }
set
{
Settings.Current.MusicVolume = value;
if (currentPlayingMusic != null)
currentPlayingMusic.Volume = value; //ncrunch: no coverage
}
}
}
}