Added audio playback to the AssetBrowser
This commit is contained in:
committed by
Matthias Mailänder
parent
7a9e0863d6
commit
8b944e9c82
@@ -165,6 +165,14 @@ namespace OpenRA
|
||||
return Play(type, player, names.Random(world.LocalRandom), false, pos, volumeModifier);
|
||||
}
|
||||
|
||||
public ISound Play(ISoundFormat soundFormat) => Play(soundFormat, MusicVolume);
|
||||
|
||||
public ISound Play(ISoundFormat soundFormat, float volume)
|
||||
{
|
||||
return soundEngine.Play2DStream(soundFormat.GetPCMInputStream(), soundFormat.Channels, soundFormat.SampleBits, soundFormat.SampleRate,
|
||||
false, true, WPos.Zero, volume);
|
||||
}
|
||||
|
||||
public void PlayVideo(byte[] raw, int channels, int sampleBits, int sampleRate)
|
||||
{
|
||||
StopVideo();
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace OpenRA
|
||||
{
|
||||
public readonly string[] SpriteExtensions = Array.Empty<string>();
|
||||
public readonly string[] ModelExtensions = Array.Empty<string>();
|
||||
public readonly string[] AudioExtensions = Array.Empty<string>();
|
||||
public readonly string[] VideoExtensions = Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
readonly string[] allowedExtensions;
|
||||
readonly string[] allowedSpriteExtensions;
|
||||
readonly string[] allowedModelExtensions;
|
||||
readonly string[] allowedAudioExtensions;
|
||||
readonly string[] allowedVideoExtensions;
|
||||
readonly IEnumerable<IReadOnlyPackage> acceptablePackages;
|
||||
readonly string[] palettes;
|
||||
@@ -48,6 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
IReadOnlyPackage currentPackage;
|
||||
Sprite[] currentSprites;
|
||||
IModel currentVoxel;
|
||||
ISound currentSound;
|
||||
VideoPlayerWidget player = null;
|
||||
bool isVideoLoaded = false;
|
||||
bool isLoadError = false;
|
||||
@@ -77,7 +79,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
ticker.OnTick = () =>
|
||||
{
|
||||
if (animateFrames)
|
||||
if (animateFrames && currentSprites != null)
|
||||
SelectNextFrame();
|
||||
};
|
||||
}
|
||||
@@ -310,9 +312,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var assetBrowserModData = modData.Manifest.Get<AssetBrowser>();
|
||||
allowedSpriteExtensions = assetBrowserModData.SpriteExtensions;
|
||||
allowedModelExtensions = assetBrowserModData.ModelExtensions;
|
||||
allowedAudioExtensions = assetBrowserModData.AudioExtensions;
|
||||
allowedVideoExtensions = assetBrowserModData.VideoExtensions;
|
||||
allowedExtensions = allowedSpriteExtensions
|
||||
.Union(allowedModelExtensions)
|
||||
.Union(allowedAudioExtensions)
|
||||
.Union(allowedVideoExtensions)
|
||||
.ToArray();
|
||||
|
||||
@@ -402,6 +406,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
bool LoadAsset(IReadOnlyPackage package, string filename)
|
||||
{
|
||||
if (currentSound != null)
|
||||
Game.Sound.StopSound(currentSound);
|
||||
|
||||
currentSprites = null;
|
||||
currentFrame = 0;
|
||||
currentVoxel = null;
|
||||
currentSound = null;
|
||||
|
||||
if (isVideoLoaded)
|
||||
{
|
||||
player.Stop();
|
||||
@@ -456,6 +468,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
// Just in case we're switching away from a type of asset that forced the music to pause.
|
||||
UnMuteSounds();
|
||||
}
|
||||
else if (allowedAudioExtensions.Contains(fileExtension))
|
||||
{
|
||||
// Mute music so it doesn't interfere with current asset.
|
||||
MuteSounds();
|
||||
|
||||
using (var soundStream = Game.ModData.DefaultFileSystem.Open(prefix + filename))
|
||||
foreach (var modDataSoundLoader in Game.ModData.SoundLoaders)
|
||||
if (modDataSoundLoader.TryParseSound(soundStream, out var soundFormat))
|
||||
currentSound = Game.Sound.Play(soundFormat, Game.Sound.SoundVolume);
|
||||
}
|
||||
else if (allowedVideoExtensions.Contains(fileExtension))
|
||||
{
|
||||
var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders);
|
||||
|
||||
@@ -240,6 +240,7 @@ ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SpriteExtensions: .shp, .tem, .des, .sno, .jun
|
||||
AudioExtensions: .aud, .wav
|
||||
VideoExtensions: .vqa, .wsa
|
||||
|
||||
GameSpeeds:
|
||||
|
||||
@@ -215,6 +215,7 @@ ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SpriteExtensions: .shp, .r8
|
||||
AudioExtensions: .aud, .wav
|
||||
VideoExtensions: .vqa
|
||||
|
||||
GameSpeeds:
|
||||
|
||||
@@ -245,6 +245,7 @@ ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SpriteExtensions: .shp, .tmp, .tem, .des, .sno, .int
|
||||
AudioExtensions: .aud, .wav
|
||||
VideoExtensions: .vqa, .wsa
|
||||
|
||||
GameSpeeds:
|
||||
|
||||
@@ -274,6 +274,7 @@ ModelSequenceFormat: VoxelModelSequence
|
||||
AssetBrowser:
|
||||
SpriteExtensions: .shp, .tem, .sno
|
||||
ModelExtensions: .vxl
|
||||
AudioExtensions: .aud, .wav
|
||||
VideoExtensions: .vqa
|
||||
|
||||
GameSpeeds:
|
||||
|
||||
Reference in New Issue
Block a user