mirror of
https://github.com/LNH-team/pico-launcher.git
synced 2026-06-02 09:06:54 +02:00
Initial commit
This commit is contained in:
44
arm9/source/bgm/BgmService.cpp
Normal file
44
arm9/source/bgm/BgmService.cpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#include "common.h"
|
||||
#include "core/mini-printf.h"
|
||||
#include "Pcm16FileAudioStream.h"
|
||||
#include "BcstmAudioStream.h"
|
||||
#include "romBrowser/SdFolder.h"
|
||||
#include "romBrowser/SdFolderFactory.h"
|
||||
#include "romBrowser/FileType/NullFileTypeProvider.h"
|
||||
#include "BgmService.h"
|
||||
|
||||
bool BgmService::StartBgm(const TCHAR* filePath)
|
||||
{
|
||||
auto stream = std::make_unique<BcstmAudioStream>();
|
||||
if (!stream->Open(filePath))
|
||||
return false;
|
||||
|
||||
return _audioStreamPlayer->StartPlayback(std::move(stream));
|
||||
}
|
||||
|
||||
void BgmService::StartBgmFromConfig()
|
||||
{
|
||||
TCHAR pathBuffer[128];
|
||||
mini_snprintf(pathBuffer, sizeof(pathBuffer), "/_pico/themes/%s/bgm", _appSettingsService.GetAppSettings().theme.GetString());
|
||||
NullFileTypeProvider fileTypeProvider;
|
||||
auto bgmFolder = SdFolderFactory(&fileTypeProvider).CreateFromPath(pathBuffer);
|
||||
if (!bgmFolder || bgmFolder->GetFileCount() == 0)
|
||||
{
|
||||
StopBgm();
|
||||
return;
|
||||
}
|
||||
u32 bgmToPlay = _randomGenerator.NextU32(bgmFolder->GetFileCount());
|
||||
auto stream = std::make_unique<BcstmAudioStream>();
|
||||
if (!stream->Open(bgmFolder->GetFiles()[bgmToPlay]->GetFastFileRef()))
|
||||
{
|
||||
StopBgm();
|
||||
return;
|
||||
}
|
||||
|
||||
_audioStreamPlayer->StartPlayback(std::move(stream));
|
||||
}
|
||||
|
||||
void BgmService::StopBgm()
|
||||
{
|
||||
_audioStreamPlayer->StopPlayback();
|
||||
}
|
||||
Reference in New Issue
Block a user