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 Track track = _playlist.tracks().at(_current);
66 _player->setCurrentSource(Phonon::MediaSource(track.source()));
67 emit trackChanged(track);
71 if (_history.count() > 0)
72 _current = _history.pop();
77 void Player::_stateChanged(Phonon::State newState, Phonon::State oldState) {
79 case Phonon::PlayingState:
80 if (_state == PLAYER_LOADING) {
81 _state = PLAYER_PLAYING;
82 emit stateChanged(_state);
85 case Phonon::StoppedState:
87 case Phonon::LoadingState:
89 case Phonon::PausedState:
90 if (_state == PLAYER_PLAYING) {
92 } else if (_state == PLAYER_ERROR) {
96 case Phonon::BufferingState:
98 case Phonon::ErrorState:
99 _state = PLAYER_ERROR;
100 qDebug() << _player->errorString();
105 void Player::_tick(qint64 ticks) {
106 emit tick(ticks/1000, _playlist.tracks().at(_current).metadata().length());
109 void Player::setPlaylist(Playlist playlist) {
110 _playlist = playlist;
114 void Player::seek(int s) {
115 _player->seek(s*1000);