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);
|
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)
|
public void PlayVideo(byte[] raw, int channels, int sampleBits, int sampleRate)
|
||||||
{
|
{
|
||||||
StopVideo();
|
StopVideo();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
public readonly string[] SpriteExtensions = Array.Empty<string>();
|
public readonly string[] SpriteExtensions = Array.Empty<string>();
|
||||||
public readonly string[] ModelExtensions = Array.Empty<string>();
|
public readonly string[] ModelExtensions = Array.Empty<string>();
|
||||||
|
public readonly string[] AudioExtensions = Array.Empty<string>();
|
||||||
public readonly string[] VideoExtensions = 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[] allowedExtensions;
|
||||||
readonly string[] allowedSpriteExtensions;
|
readonly string[] allowedSpriteExtensions;
|
||||||
readonly string[] allowedModelExtensions;
|
readonly string[] allowedModelExtensions;
|
||||||
|
readonly string[] allowedAudioExtensions;
|
||||||
readonly string[] allowedVideoExtensions;
|
readonly string[] allowedVideoExtensions;
|
||||||
readonly IEnumerable<IReadOnlyPackage> acceptablePackages;
|
readonly IEnumerable<IReadOnlyPackage> acceptablePackages;
|
||||||
readonly string[] palettes;
|
readonly string[] palettes;
|
||||||
@@ -48,6 +49,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
IReadOnlyPackage currentPackage;
|
IReadOnlyPackage currentPackage;
|
||||||
Sprite[] currentSprites;
|
Sprite[] currentSprites;
|
||||||
IModel currentVoxel;
|
IModel currentVoxel;
|
||||||
|
ISound currentSound;
|
||||||
VideoPlayerWidget player = null;
|
VideoPlayerWidget player = null;
|
||||||
bool isVideoLoaded = false;
|
bool isVideoLoaded = false;
|
||||||
bool isLoadError = false;
|
bool isLoadError = false;
|
||||||
@@ -77,7 +79,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
ticker.OnTick = () =>
|
ticker.OnTick = () =>
|
||||||
{
|
{
|
||||||
if (animateFrames)
|
if (animateFrames && currentSprites != null)
|
||||||
SelectNextFrame();
|
SelectNextFrame();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -310,9 +312,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var assetBrowserModData = modData.Manifest.Get<AssetBrowser>();
|
var assetBrowserModData = modData.Manifest.Get<AssetBrowser>();
|
||||||
allowedSpriteExtensions = assetBrowserModData.SpriteExtensions;
|
allowedSpriteExtensions = assetBrowserModData.SpriteExtensions;
|
||||||
allowedModelExtensions = assetBrowserModData.ModelExtensions;
|
allowedModelExtensions = assetBrowserModData.ModelExtensions;
|
||||||
|
allowedAudioExtensions = assetBrowserModData.AudioExtensions;
|
||||||
allowedVideoExtensions = assetBrowserModData.VideoExtensions;
|
allowedVideoExtensions = assetBrowserModData.VideoExtensions;
|
||||||
allowedExtensions = allowedSpriteExtensions
|
allowedExtensions = allowedSpriteExtensions
|
||||||
.Union(allowedModelExtensions)
|
.Union(allowedModelExtensions)
|
||||||
|
.Union(allowedAudioExtensions)
|
||||||
.Union(allowedVideoExtensions)
|
.Union(allowedVideoExtensions)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
|
|
||||||
@@ -402,6 +406,14 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
bool LoadAsset(IReadOnlyPackage package, string filename)
|
bool LoadAsset(IReadOnlyPackage package, string filename)
|
||||||
{
|
{
|
||||||
|
if (currentSound != null)
|
||||||
|
Game.Sound.StopSound(currentSound);
|
||||||
|
|
||||||
|
currentSprites = null;
|
||||||
|
currentFrame = 0;
|
||||||
|
currentVoxel = null;
|
||||||
|
currentSound = null;
|
||||||
|
|
||||||
if (isVideoLoaded)
|
if (isVideoLoaded)
|
||||||
{
|
{
|
||||||
player.Stop();
|
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.
|
// Just in case we're switching away from a type of asset that forced the music to pause.
|
||||||
UnMuteSounds();
|
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))
|
else if (allowedVideoExtensions.Contains(fileExtension))
|
||||||
{
|
{
|
||||||
var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders);
|
var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders);
|
||||||
|
|||||||
@@ -240,6 +240,7 @@ ModelSequenceFormat: PlaceholderModelSequence
|
|||||||
|
|
||||||
AssetBrowser:
|
AssetBrowser:
|
||||||
SpriteExtensions: .shp, .tem, .des, .sno, .jun
|
SpriteExtensions: .shp, .tem, .des, .sno, .jun
|
||||||
|
AudioExtensions: .aud, .wav
|
||||||
VideoExtensions: .vqa, .wsa
|
VideoExtensions: .vqa, .wsa
|
||||||
|
|
||||||
GameSpeeds:
|
GameSpeeds:
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ ModelSequenceFormat: PlaceholderModelSequence
|
|||||||
|
|
||||||
AssetBrowser:
|
AssetBrowser:
|
||||||
SpriteExtensions: .shp, .r8
|
SpriteExtensions: .shp, .r8
|
||||||
|
AudioExtensions: .aud, .wav
|
||||||
VideoExtensions: .vqa
|
VideoExtensions: .vqa
|
||||||
|
|
||||||
GameSpeeds:
|
GameSpeeds:
|
||||||
|
|||||||
@@ -245,6 +245,7 @@ ModelSequenceFormat: PlaceholderModelSequence
|
|||||||
|
|
||||||
AssetBrowser:
|
AssetBrowser:
|
||||||
SpriteExtensions: .shp, .tmp, .tem, .des, .sno, .int
|
SpriteExtensions: .shp, .tmp, .tem, .des, .sno, .int
|
||||||
|
AudioExtensions: .aud, .wav
|
||||||
VideoExtensions: .vqa, .wsa
|
VideoExtensions: .vqa, .wsa
|
||||||
|
|
||||||
GameSpeeds:
|
GameSpeeds:
|
||||||
|
|||||||
@@ -274,6 +274,7 @@ ModelSequenceFormat: VoxelModelSequence
|
|||||||
AssetBrowser:
|
AssetBrowser:
|
||||||
SpriteExtensions: .shp, .tem, .sno
|
SpriteExtensions: .shp, .tem, .sno
|
||||||
ModelExtensions: .vxl
|
ModelExtensions: .vxl
|
||||||
|
AudioExtensions: .aud, .wav
|
||||||
VideoExtensions: .vqa
|
VideoExtensions: .vqa
|
||||||
|
|
||||||
GameSpeeds:
|
GameSpeeds:
|
||||||
|
|||||||
Reference in New Issue
Block a user