2 #include <phonon/MediaSource>
4 using namespace SomePlayer::Playback;
5 using namespace SomePlayer::DataObjects;
7 Player::Player(QObject *parent) :
10 _player = new Phonon::MediaObject(this);
11 _output = new Phonon::AudioOutput(Phonon::MusicCategory, this);
12 _player->setTickInterval(1000);
13 connect(_player, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(_stateChanged(Phonon::State,Phonon::State)));
14 connect(_player, SIGNAL(tick(qint64)), this, SLOT(_tick(qint64)));
15 Phonon::createPath(_player, _output);
16 int seed = reinterpret_cast<int> (_player);
22 void Player::setTrackId(int id) {
24 _history.push(_current);
26 _state = PLAYER_LOADING;
27 emit stateChanged(_state);
32 _state = PLAYER_PLAYING;
33 emit stateChanged(_state);
38 _state = PLAYER_STOPPED;
39 emit stateChanged(_state);
42 void Player::pause() {
44 _state = PLAYER_PAUSED;
45 emit stateChanged(_state);
49 _history.push(_current);
51 _current = rand() % _playlist.tracks().count();
53 _current = (_current + 1) % _playlist.tracks().count();
55 if (_history.count()-1 == _playlist.tracks().count() && !_repeat) {
64 void Player::_set_source() {
65 qDebug() << "id: " << _current << " all: " << _playlist.tracks().count();
66 Track track = _playlist.tracks().at(_current);
67 _player->setCurrentSource(Phonon::MediaSource(track.source()));
68 emit trackChanged(track);
72 if (_history.count() > 0)
73 _current = _history.pop();
78 void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) {
79 qDebug() << "state changed: " << oldState << "->" << newState;
81 case Phonon::PlayingState:
82 if (_state == PLAYER_LOADING) {
83 _state = PLAYER_PLAYING;
84 emit stateChanged(_state);
87 case Phonon::StoppedState:
89 case Phonon::LoadingState:
91 case Phonon::PausedState:
92 if (_state == PLAYER_PLAYING) {
94 } else if (_state == PLAYER_ERROR) {
98 case Phonon::BufferingState:
100 case Phonon::ErrorState:
101 _state = PLAYER_ERROR;
102 qDebug() << _player->errorString();
107 void Player::_tick(qint64 ticks) {
108 emit tick(ticks/1000, _playlist.tracks().at(_current).metadata().length());
111 void Player::setPlaylist(Playlist playlist) {
112 _playlist = playlist;
116 void Player::seek(int s) {
117 qDebug() << "seeking " << s;
118 _player->seek(s*1000);