Created separate directory for player engine
[someplayer] / src / player / player.cpp
1 #include "player.h"
2 #include <phonon/MediaSource>
3
4 using namespace SomePlayer::Playback;
5 using namespace SomePlayer::DataObjects;
6
7 Player::Player(QObject *parent) :
8     QObject(parent)
9 {
10         _player = NULL;
11 }
12
13 void Player::setTrack(Track &track) {
14         _current_track = track;
15         _create_player();
16         emit stateChanged(PLAYER_LOADING);
17 }
18
19 void Player::play() {
20         if (_player) {
21                 _player->play();
22                 emit stateChanged(PLAYER_PLAYING);
23         }
24 }
25
26 void Player::stop() {
27         if (_player) {
28                 _player->stop();
29                 emit stateChanged(PLAYER_STOPPED);
30         }
31 }
32
33 void Player::pause() {
34         if (_player) {
35                 _player->pause();
36                 emit stateChanged(PLAYER_PAUSED);
37         }
38 }
39
40 void Player::_create_player() {
41         if (_player) {
42                 disconnect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(_stateChanged(Phonon::State,Phonon::State)));
43                 delete _player;
44         }
45         _player = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(_current_track.source()));
46         _player->setTickInterval(1000);
47         connect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(_stateChanged(Phonon::State,Phonon::State)));
48         connect(_player, SIGNAL(tick(qint64)), this, SLOT(_tick(qint64)));
49         emit stateChanged(PLAYER_STOPPED);
50 }
51
52 void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) {
53 }
54
55 void Player::_tick(qint64 ticks) {
56         emit tick(ticks/1000, _current_track.metadata().length());
57 }