forked from drtchops/LiveSplit.Skyrim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaPlayer.cs
More file actions
61 lines (52 loc) · 1.41 KB
/
MediaPlayer.cs
File metadata and controls
61 lines (52 loc) · 1.41 KB
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
using LiveSplit.Options;
using NAudio.Wave;
using System;
using System.IO;
using System.Threading.Tasks;
namespace LiveSplit.Skyrim
{
public class MediaPlayer
{
public int GeneralVolume { get; set; }
protected WaveOut Player { get; private set; }
public MediaPlayer()
{
GeneralVolume = 100;
Player = new WaveOut();
}
public void Dispose()
{
Player.Stop();
}
public void PlaySound(String location, int volume)
{
Player.Stop();
if (File.Exists(location))
{
Task.Factory.StartNew(() =>
{
try
{
AudioFileReader audioFileReader = new AudioFileReader(location);
audioFileReader.Volume = (volume / 100f) * (GeneralVolume / 100f);
Player.DeviceNumber = -1;
Player.Init(audioFileReader);
Player.Play();
}
catch (Exception e)
{
Log.Error(e);
}
});
}
}
public void PlaySound(String location)
{
PlaySound(location, GeneralVolume);
}
public void Stop()
{
Player.Stop();
}
}
}