-added ability for music plugin to play playlist files (.pls or .m3u)

edit your music plugin ini. change the filetypes line to include .pls for example:
filetypes=.mp3|.ogg|.pls|.m3u
This commit is contained in:
Fledge68 2018-11-03 10:03:58 -05:00
parent 796a8d78f7
commit c48ea85348
4 changed files with 62 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

After

Width:  |  Height:  |  Size: 3.3 MiB

View File

@ -1052,7 +1052,10 @@ void CMenu::_launch(const dir_discHdr *hdr)
/* check if music player plugin, if so set wiiflow's bckgrnd music player to play this song */ /* check if music player plugin, if so set wiiflow's bckgrnd music player to play this song */
if(plugin_dol_len == 5 && strcasecmp(plugin_dol_name, "music") == 0) if(plugin_dol_len == 5 && strcasecmp(plugin_dol_name, "music") == 0)
{ {
if(strstr(launchHdr.path, ".pls") == NULL && strstr(launchHdr.path, ".m3u") == NULL)
MusicPlayer.LoadFile(launchHdr.path, false); MusicPlayer.LoadFile(launchHdr.path, false);
else
MusicPlayer.InitPlaylist(m_cfg, launchHdr.path, currentPartition);// maybe error msg if trouble loading playlist
m_exit = false; m_exit = false;
return; return;
} }

View File

@ -16,8 +16,11 @@
****************************************************************************/ ****************************************************************************/
#include <cstdio> #include <cstdio>
#include <algorithm> #include <algorithm>
#include <fstream>
#include "MusicPlayer.hpp" #include "MusicPlayer.hpp"
#include "SoundHandler.hpp" #include "SoundHandler.hpp"
#include "devicemounter/DeviceHandler.hpp"
#include "list/ListGenerator.hpp" #include "list/ListGenerator.hpp"
#include "gui/text.hpp" #include "gui/text.hpp"
#include "gecko/gecko.hpp" #include "gecko/gecko.hpp"
@ -46,6 +49,11 @@ static inline void FileNameAdder(char *Path)
void Musicplayer::Init(Config &cfg, const string& musicDir, const string& themeMusicDir) void Musicplayer::Init(Config &cfg, const string& musicDir, const string& themeMusicDir)
{ {
if(usingPlaylist)
{
InitPlaylist(cfg, curPlaylist, pl_device);
return;
}
Cleanup(); Cleanup();
FadeRate = cfg.getInt("GENERAL", "music_fade_rate", 8); FadeRate = cfg.getInt("GENERAL", "music_fade_rate", 8);
Volume = cfg.getInt("GENERAL", "sound_volume_music", 255); Volume = cfg.getInt("GENERAL", "sound_volume_music", 255);
@ -61,10 +69,55 @@ void Musicplayer::Init(Config &cfg, const string& musicDir, const string& themeM
srand(unsigned(time(NULL))); srand(unsigned(time(NULL)));
random_shuffle(FileNames.begin(), FileNames.end()); random_shuffle(FileNames.begin(), FileNames.end());
} }
usingPlaylist = false;
OneSong = (FileNames.size() == 1); OneSong = (FileNames.size() == 1);
CurrentFileName = FileNames.begin(); CurrentFileName = FileNames.begin();
} }
int Musicplayer::InitPlaylist(Config &cfg, const char *playlist, u8 device)
{
ifstream filestr;
filestr.open(playlist);
if(filestr.fail())
return 0;
filestr.seekg(0,ios_base::end);
int size = filestr.tellg();
if(size <= 0)
return -1;
filestr.seekg(0,ios_base::beg);
string song;
FileNames.clear();
while(!filestr.eof())
{
getline(filestr, song, '\r');
if(song.find(".mp3") == string::npos && song.find(".ogg") == string::npos)// if not song path continue to next line
continue;
while(song.find("\\") != string::npos)// convert all '\' to '/'
song.replace(song.find("\\"), 1, "/");
string::size_type p = song.find("/");// remove drive letter and anything else before first /
song.erase(0, p);
const char *songPath = fmt("%s:%s", DeviceName[device], song.c_str());
FileNames.push_back(songPath);
}
filestr.close();
curPlaylist = playlist;
usingPlaylist = true;
pl_device = device;
if(cfg.getBool("GENERAL", "randomize_music", true) && FileNames.size() > 0)
{
srand(unsigned(time(NULL)));
random_shuffle(FileNames.begin(), FileNames.end());
}
OneSong = (FileNames.size() == 1);
CurrentFileName = FileNames.begin();
LoadCurrentFile();
return 1;
}
void Musicplayer::SetFadeRate(u8 faderate) void Musicplayer::SetFadeRate(u8 faderate)
{ {
FadeRate = faderate; FadeRate = faderate;
@ -123,7 +176,7 @@ void Musicplayer::Stop()
{ {
if(!MusicFile.IsPlaying()) if(!MusicFile.IsPlaying())
return; return;
MusicFile.Pause(); MusicFile.Pause();// why not Stop()
CurrentPosition = SoundHandle.Decoder(MusicFile.GetVoice())->Tell(); CurrentPosition = SoundHandle.Decoder(MusicFile.GetVoice())->Tell();
MusicFile.FreeMemory(); MusicFile.FreeMemory();
MusicStopped = true; MusicStopped = true;

View File

@ -29,6 +29,7 @@ class Musicplayer
public: public:
void Cleanup(); void Cleanup();
void Init(Config &cfg, const string& musicDir, const string& themeMusicDir); void Init(Config &cfg, const string& musicDir, const string& themeMusicDir);
int InitPlaylist(Config &cfg, const char *playlist, u8 device);
void Tick(bool attenuate); void Tick(bool attenuate);
void SetFadeRate(u8 faderate); void SetFadeRate(u8 faderate);
@ -60,6 +61,9 @@ protected:
int CurrentPosition; int CurrentPosition;
bool MusicStopped; bool MusicStopped;
bool MusicChanged; bool MusicChanged;
const char *curPlaylist;
bool usingPlaylist = false;
u8 pl_device;
GuiSound MusicFile; GuiSound MusicFile;
}; };