forked from bijington/orbit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/building-games-in-maui
- Loading branch information
Showing
12 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Orbit.Audio; | ||
|
||
public static class AudioItem | ||
{ | ||
public const string HomeBackgroundMusic = "magic-space.mp3"; | ||
|
||
public const string ThrusterSoundEffect = "engine-heavy-loop.mp3"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using Plugin.Maui.Audio; | ||
|
||
namespace Orbit.Audio; | ||
|
||
public class AudioService | ||
{ | ||
readonly IDictionary<string, IAudioPlayer> players = new Dictionary<string, IAudioPlayer>(); | ||
private readonly IAudioManager audioManager; | ||
private readonly IFileSystem fileSystem; | ||
|
||
public AudioService( | ||
IAudioManager audioManager, | ||
IFileSystem fileSystem) | ||
{ | ||
this.audioManager = audioManager; | ||
this.fileSystem = fileSystem; | ||
} | ||
|
||
public async Task Play(string audioItem, bool loop) | ||
{ | ||
if (!players.TryGetValue(audioItem, out var audioPlayer)) | ||
{ | ||
audioPlayer = audioManager.CreatePlayer(await fileSystem.OpenAppPackageFileAsync(audioItem)); | ||
|
||
players[audioItem] = audioPlayer; | ||
|
||
audioPlayer.Loop = loop; | ||
} | ||
|
||
if (!audioPlayer.IsPlaying) | ||
{ | ||
audioPlayer.Play(); | ||
} | ||
} | ||
|
||
public void Stop(string audioItem) | ||
{ | ||
if (players.TryGetValue(audioItem, out var audioPlayer)) | ||
{ | ||
if (audioPlayer.IsPlaying) | ||
{ | ||
audioPlayer.Stop(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Orbit.Audio; | ||
|
||
public enum SoundEffect | ||
{ | ||
Thruster | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Plugin.Maui.Audio; | ||
|
||
namespace Orbit.Audio; | ||
|
||
public class SoundEffectService | ||
{ | ||
static readonly IDictionary<SoundEffect, string> soundEffectToResourceMapping = new Dictionary<SoundEffect, string>() | ||
{ | ||
[SoundEffect.Thruster] = "engine-heavy-loop.mp3" | ||
}; | ||
|
||
public static string GetSoundEffectFile(SoundEffect soundEffect) => | ||
soundEffectToResourceMapping[soundEffect]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.