mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-28 11:20:53 +00:00
Changed: Implement mp3 player playlist
This commit is contained in:
parent
848374b5ef
commit
a9a640753e
3 changed files with 117 additions and 19 deletions
|
@ -25,23 +25,38 @@
|
|||
<group type="menu"
|
||||
id="mp3_player_menu"
|
||||
extends="base_menu_with_color"></group>
|
||||
|
||||
<template name="playlist_song" keep="true" id="" posparent="parent" posref="TL TL" w="206" h="20" line_maxw="160" index="0">
|
||||
<group id="#id" w="#w" child_resize_h="true" posparent="#posparent" posref="#posref" group_onclick_r="" group_params_r="">
|
||||
<ctrl type="button" id="btn" button_type="toggle_button" sizeref="wh" tx_normal="blank.tga" tx_pushed="blank.tga" tx_over="blank.tga" scale="true"
|
||||
color="255 255 255 0" col_pushed="255 255 255 0" col_over="255 255 255 90"
|
||||
global_color_normal="true" global_color_pushed="true" global_color_over="true"
|
||||
ondblclick_l="music_player" params_dblclick_l="song=#index" />
|
||||
|
||||
<view type="text" id="title" posref="ML ML" x="0" line_maxw="#line_maxw" fontsize="8" shadow="true" multi_line="true" multi_line_space="0" />
|
||||
<view type="text" id="duration" posref="MR MR" x="0" fontsize="8" shadow="true" color="255 255 255 128" />
|
||||
</group>
|
||||
</template>
|
||||
|
||||
<group type="modal"
|
||||
id="playlist"
|
||||
posparent="mp3_player"
|
||||
posref="BM TM"
|
||||
w="234"
|
||||
h="256"
|
||||
max_h="250"
|
||||
child_resize_h="true"
|
||||
child_resize_hmargin="10"
|
||||
options="layer0"
|
||||
mouse_pos="false"
|
||||
escapable="false"
|
||||
exit_click_out="false"
|
||||
escapable="true"
|
||||
exit_click_out="true"
|
||||
on_active=""
|
||||
on_active_params="">
|
||||
<view type="text"
|
||||
id="title"
|
||||
posref="TL TL"
|
||||
x="4"
|
||||
y="-4"
|
||||
x="8"
|
||||
y="-8"
|
||||
hardtext="uiPlaylistTitle"
|
||||
shadow="true"
|
||||
color="255 255 255 255"
|
||||
|
@ -50,14 +65,33 @@
|
|||
id="close"
|
||||
button_type="push_button"
|
||||
posref="TR TR"
|
||||
x="-4"
|
||||
y="-4"
|
||||
x="-8"
|
||||
y="-8"
|
||||
tx_normal="w_win_close.tga"
|
||||
tx_pushed="w_win_close.tga"
|
||||
tx_over="W_button_14_over.tga"
|
||||
onclick_l="leave_modal"
|
||||
params_l="" />
|
||||
<ctrl style="text_button_header"
|
||||
button_type="push_button"
|
||||
id="refresh"
|
||||
posparent="close"
|
||||
posref="ML MR"
|
||||
x="-4"
|
||||
y="0"
|
||||
hardtext="uiPlaylistRefresh"
|
||||
onclick_l="music_player"
|
||||
params_l="play_songs" />
|
||||
|
||||
<group id="content" x="8" y="-24" over="true" sizeref="w" posref="TL TL" child_resize_h="true" child_resize_hmargin="4">
|
||||
<group id="songs" x="10" y="0" sizeref="w" posref="TL TL" child_resize_h="true" max_h="215">
|
||||
<group id="list" type="list" x="0" y="0" posref="TL TL" />
|
||||
</group>
|
||||
<ctrl style="skin_scroll" id="sv" posref="TL TL" target="songs" />
|
||||
</group>
|
||||
</group>
|
||||
<tree node="playlist" />
|
||||
|
||||
<link expr="@UI:SAVE:MP3_VOLUME"
|
||||
action="music_player"
|
||||
params="volume=@UI:SAVE:MP3_VOLUME" />
|
||||
|
@ -223,12 +257,12 @@
|
|||
button_type="push_button"
|
||||
posref="MM MM"
|
||||
posparent="slot5"
|
||||
tx_normal="mp3_button_open.tga"
|
||||
tx_pushed="mp3_button_open.tga"
|
||||
tx_normal="mp3_button_list.tga"
|
||||
tx_pushed="mp3_button_list.tga"
|
||||
tx_over="mp3_button_over.tga"
|
||||
onclick_l="music_player"
|
||||
params_l="play_songs"
|
||||
tooltip="uiMP3Open" />
|
||||
onclick_l="enter_modal"
|
||||
params_l="group=ui:interface:playlist"
|
||||
tooltip="uiMP3Playlist" />
|
||||
<!--
|
||||
<ctrl type="button" id="but_list" button_type="push_button" posref="MM MM" posparent="slot6"
|
||||
tx_normal="mp3_button_list.tga" tx_pushed="mp3_button_list.tga" tx_over="mp3_button_over.tga"
|
||||
|
|
|
@ -34,6 +34,12 @@ using namespace NL3D;
|
|||
|
||||
extern UDriver *Driver;
|
||||
|
||||
// xml element ids
|
||||
#define MP3_PLAYER_PLAYLIST_LIST "ui:interface:playlist:content:songs:list"
|
||||
#define TEMPLATE_PLAYLIST_SONG "playlist_song"
|
||||
#define TEMPLATE_PLAYLIST_SONG_TITLE "title"
|
||||
#define TEMPLATE_PLAYLIST_SONG_DURATION "duration"
|
||||
|
||||
static const std::string MediaPlayerDirectory("music/");
|
||||
|
||||
CMusicPlayer MusicPlayer;
|
||||
|
@ -48,27 +54,76 @@ CMusicPlayer::CMusicPlayer ()
|
|||
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
void CMusicPlayer::playSongs (const std::vector<CSongs> &songs)
|
||||
{
|
||||
_Songs = songs;
|
||||
_CurrentSong = 0;
|
||||
|
||||
// reset song index if out of bounds
|
||||
if (_CurrentSong > _Songs.size())
|
||||
_CurrentSong = 0;
|
||||
|
||||
CGroupList *pList = dynamic_cast<CGroupList *>(CWidgetManager::getInstance()->getElementFromId(MP3_PLAYER_PLAYLIST_LIST));
|
||||
if (pList)
|
||||
{
|
||||
pList->clearGroups();
|
||||
pList->setDynamicDisplaySize(true);
|
||||
for (uint i=0; i < _Songs.size(); ++i)
|
||||
{
|
||||
uint min = (sint32)(_Songs[i].Length / 60) % 60;
|
||||
uint sec = (sint32)(_Songs[i].Length) % 60;
|
||||
uint hour = _Songs[i].Length / 3600;
|
||||
std::string duration(toString("%02d:%02d", min, sec));
|
||||
if (hour > 0)
|
||||
duration = toString("%02d:", hour) + duration;
|
||||
|
||||
vector< pair<string, string> > vParams;
|
||||
vParams.push_back(pair<string, string>("id", "s" + toString(i)));
|
||||
vParams.push_back(pair<string, string>("index", toString(i)));
|
||||
CInterfaceGroup *pNew = CWidgetManager::getInstance()->getParser()->createGroupInstance(TEMPLATE_PLAYLIST_SONG, pList->getId(), vParams);
|
||||
if (pNew)
|
||||
{
|
||||
CViewText *pVT = dynamic_cast<CViewText *>(pNew->getView(TEMPLATE_PLAYLIST_SONG_TITLE));
|
||||
if (pVT)
|
||||
{
|
||||
ucstring title;
|
||||
title.fromUtf8(_Songs[i].Title);
|
||||
pVT->setText(title);
|
||||
}
|
||||
|
||||
pVT = dynamic_cast<CViewText *>(pNew->getView(TEMPLATE_PLAYLIST_SONG_DURATION));
|
||||
if (pVT)
|
||||
{
|
||||
pVT->setText(duration);
|
||||
}
|
||||
|
||||
pNew->setParent(pList);
|
||||
pList->addChild(pNew);
|
||||
}
|
||||
}
|
||||
pList->invalidateCoords();
|
||||
}
|
||||
|
||||
// If pause, stop, else play will resume
|
||||
if (_State == Paused)
|
||||
_State = Stopped;
|
||||
|
||||
play ();
|
||||
}
|
||||
|
||||
|
||||
// ***************************************************************************
|
||||
|
||||
void CMusicPlayer::play ()
|
||||
void CMusicPlayer::play (sint index)
|
||||
{
|
||||
if(!SoundMngr)
|
||||
return;
|
||||
|
||||
if (index >= 0 && index < _Songs.size())
|
||||
{
|
||||
if (_State == Paused)
|
||||
stop();
|
||||
|
||||
_CurrentSong = index;
|
||||
}
|
||||
|
||||
if (!_Songs.empty())
|
||||
{
|
||||
nlassert (_CurrentSong<_Songs.size());
|
||||
|
@ -300,7 +355,7 @@ public:
|
|||
|
||||
CMusicPlayer::CSongs song;
|
||||
song.Filename = filenames[i];
|
||||
SoundMngr->getMixer()->getSongTitle(filenames[i], song.Title);
|
||||
SoundMngr->getMixer()->getSongTitle(filenames[i], song.Title, song.Length);
|
||||
songs.push_back (song);
|
||||
}
|
||||
|
||||
|
@ -330,6 +385,14 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
string song = getParam(Params, "song");
|
||||
if (!song.empty())
|
||||
{
|
||||
sint index=0;
|
||||
fromString(song, index);
|
||||
MusicPlayer.play(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -41,10 +41,11 @@ public:
|
|||
public:
|
||||
std::string Filename;
|
||||
std::string Title;
|
||||
float Length;
|
||||
};
|
||||
|
||||
void playSongs (const std::vector<CSongs> &songs);
|
||||
void play (); // Play the song at current position, if playing, restart. If paused, resume.
|
||||
void play (sint index = -1); // Play the song at current position, if playing, restart. If paused, resume.
|
||||
void pause ();
|
||||
void stop ();
|
||||
void previous ();
|
||||
|
|
Loading…
Reference in a new issue