[UI/MOBILE] Changed the audio player. Still WIP

This commit is contained in:
emeric
2015-12-22 15:02:21 +01:00
parent dc8fc46e21
commit feb52c3ed9
18 changed files with 372 additions and 246 deletions
+8 -47
View File
@@ -27,14 +27,13 @@
#include "logger/Logger.hpp"
#include "utils/Utils.hpp"
#include "audio/AudioPlayer.hpp"
#include "LmsApplication.hpp"
#include "ArtistSearch.hpp"
#include "ReleaseSearch.hpp"
#include "TrackSearch.hpp"
#include "TrackReleaseView.hpp"
#include "MobileAudioMediaPlayer.hpp"
#include "MobileAudio.hpp"
@@ -45,36 +44,16 @@ namespace Mobile {
using namespace Database;
static void playTrack(AudioMediaPlayer *mediaPlayer, Database::Track::id_type trackId)
static void playTrack(AudioPlayer *audioPlayer, Database::Track::id_type trackId)
{
LMS_LOG(UI, DEBUG) << "Playing track id " << trackId;
// TODO reduce transaction scope here
Wt::Dbo::Transaction transaction(DboSession());
Track::pointer track = Track::getById(DboSession(), trackId);
if (track)
{
Av::TranscodeParameters parameters;
// Determine the output format using the encoding of the player
Av::Encoding encoding;
switch(mediaPlayer->getEncoding())
{
case Wt::WMediaPlayer::MP3: encoding = Av::Encoding::MP3; break;
case Wt::WMediaPlayer::FLA: encoding = Av::Encoding::FLA; break;
case Wt::WMediaPlayer::OGA: encoding = Av::Encoding::OGA; break;
case Wt::WMediaPlayer::WEBMA: encoding = Av::Encoding::WEBMA; break;
default:
encoding = Av::Encoding::MP3;
}
parameters.setEncoding(encoding);
// TODO compute parameters using user's profile
parameters.setBitrate(Av::Stream::Type::Audio, 96000);
mediaPlayer->play(track.id(), parameters);
}
audioPlayer->loadTrack(track.id());
}
Audio::Audio(Wt::WContainerWidget *parent)
@@ -103,26 +82,8 @@ Audio::Audio(Wt::WContainerWidget *parent)
Wt::WTemplate* footer = new Wt::WTemplate(this);
footer->setTemplateText(Wt::WString::tr("mobile-audio-footer"));
// Determine the encoding to be used
Wt::WMediaPlayer::Encoding encoding;
{
Wt::Dbo::Transaction transaction (DboSession());
switch (CurrentUser()->getAudioEncoding())
{
case AudioEncoding::MP3: encoding = Wt::WMediaPlayer::MP3; break;
case AudioEncoding::WEBMA: encoding = Wt::WMediaPlayer::WEBMA; break;
case AudioEncoding::OGA: encoding = Wt::WMediaPlayer::OGA; break;
case AudioEncoding::FLA: encoding = Wt::WMediaPlayer::FLA; break;
case AudioEncoding::AUTO:
default:
encoding = AudioMediaPlayer::getBestEncoding();
}
}
AudioMediaPlayer* mediaPlayer = new AudioMediaPlayer(encoding);
footer->bindWidget("player", mediaPlayer);
AudioPlayer* audioPlayer = new AudioPlayer();
footer->bindWidget("player", audioPlayer);
edit->changed().connect(std::bind([=] ()
{
@@ -188,12 +149,12 @@ Audio::Audio(Wt::WContainerWidget *parent)
trackSearch->trackPlay().connect(std::bind([=] (Track::id_type id)
{
playTrack(mediaPlayer, id);
playTrack(audioPlayer, id);
}, std::placeholders::_1));
trackReleaseView->trackPlay().connect(std::bind([=] (Track::id_type id)
{
playTrack(mediaPlayer, id);
playTrack(audioPlayer, id);
}, std::placeholders::_1));
// Initially, populate the widgets using an empty search
@@ -1,110 +0,0 @@
/*
* Copyright (C) 2015 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WTemplate>
#include <Wt/WPushButton>
#include <Wt/WSlider>
#include "LmsApplication.hpp"
#include "MobileAudioMediaPlayer.hpp"
#include "resource/AvConvTranscodeStreamResource.hpp"
namespace UserInterface {
namespace Mobile {
Wt::WMediaPlayer::Encoding
AudioMediaPlayer::getBestEncoding()
{
// MP3 seems to be better supported everywhere
return Wt::WMediaPlayer::MP3;
}
AudioMediaPlayer::AudioMediaPlayer(Wt::WMediaPlayer::Encoding encoding, Wt::WContainerWidget *parent)
:
Wt::WContainerWidget(parent),
_player(nullptr),
_encoding(encoding)
{
Wt::WTemplate* container = new Wt::WTemplate(this);
container->setTemplateText(Wt::WString::tr("mobile-audio-player"));
Wt::WPushButton *play = new Wt::WPushButton("Play");
play->setStyleClass("btn-sm");
play->setWidth(52);
container->bindWidget("play", play);
Wt::WPushButton *pause = new Wt::WPushButton("Pause");
pause->setStyleClass("btn-sm");
pause->setWidth(52);
container->bindWidget("pause", pause);
_track = new Wt::WText("", Wt::PlainText);
_track->setStyleClass("mobile-track");
container->bindWidget("track", _track);
_artistRelease = new Wt::WText("", Wt::PlainText);
_artistRelease->setStyleClass("mobile-artist");
container->bindWidget("artist", _artistRelease);
_cover = new Wt::WImage();
container->bindWidget("cover", _cover);
_cover->setStyleClass("mobile-audio-player-cover");
_player = new Wt::WMediaPlayer(Wt::WMediaPlayer::Audio, this);
_player->addSource( _encoding, "" );
_player->setControlsWidget( 0 );
_player->setButton(Wt::WMediaPlayer::Play, play);
_player->setButton(Wt::WMediaPlayer::Pause, pause);
}
void
AudioMediaPlayer::play(Database::Track::id_type trackId, Av::TranscodeParameters parameters)
{
boost::filesystem::path path;
{
Wt::Dbo::Transaction transaction(DboSession());
Database::Track::pointer track = Database::Track::getById(DboSession(), trackId);
_track->setText( Wt::WString::fromUTF8(track->getName() ));
_artistRelease->setText( Wt::WString::fromUTF8(track->getArtist()->getName()) );
path = track->getPath();
}
// FIXME memleak here
AvConvTranscodeStreamResource *resource = new AvConvTranscodeStreamResource( path, parameters, this );
_player->clearSources();
_player->addSource( _encoding, Wt::WLink(resource));
_player->play();
_cover->setImageLink( Wt::WLink (LmsApplication::instance()->getCoverResource()->getTrackUrl(trackId, 48)));
}
} // namespace UserInterface
} // namespace Mobile
@@ -1,59 +0,0 @@
/*
* Copyright (C) 2015 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UI_AUDIO_MOBILE_MEDIA_PLAYER_HPP
#define UI_AUDIO_MOBILE_MEDIA_PLAYER_HPP
#include <Wt/WContainerWidget>
#include <Wt/WMediaPlayer>
#include <Wt/WImage>
#include "database/DatabaseHandler.hpp"
#include "av/AvTranscoder.hpp"
namespace UserInterface {
namespace Mobile {
class AudioMediaPlayer : public Wt::WContainerWidget
{
public:
static Wt::WMediaPlayer::Encoding getBestEncoding();
AudioMediaPlayer(Wt::WMediaPlayer::Encoding encoding, Wt::WContainerWidget *parent = 0);
void play(Database::Track::id_type trackId, Av::TranscodeParameters parameters);
Wt::WMediaPlayer::Encoding getEncoding() const { return _encoding; }
private:
Wt::WMediaPlayer* _player;
Wt::WMediaPlayer::Encoding _encoding;
Wt::WImage* _cover;
Wt::WText* _track;
Wt::WText* _artistRelease;
};
} // namespace UserInterface
} // namespace Mobile
#endif