Fixed bug with order of queued tracks and prev-historied tracks
[someplayer] / src / player / player.cpp
index 7eecd0e..0f11f9d 100644 (file)
@@ -17,6 +17,7 @@ Player::Player(QObject *parent) :
        qsrand(seed);
        _random = false;
        _repeat = false;
+       _current = -1;
 }
 
 void Player::setTrackId(int id) {
@@ -55,6 +56,8 @@ void Player::next() {
        _history.push(_current % count);
        if (!_queue.isEmpty()) {
                _current = _queue.dequeue();
+       } else if (!_prev_history.isEmpty()) {
+               _current = _prev_history.pop();
        } else {
                if (_random) {
                        _current = (count + (qrand()  + qrand() + qrand()) % count) % count;
@@ -81,7 +84,7 @@ void Player::_set_source() {
 
 void Player::prev() {
        if (_history.count() > 0) {
-               _queue.push_front(_current);
+               _prev_history.push(_current);
                _current = _history.pop();
                _track = _playlist.tracks().at(_current);
        }
@@ -137,9 +140,14 @@ void Player::seek(int s) {
 }
 
 void Player::play() {
-       _player->play();
        _state = PLAYER_PLAYING;
        emit stateChanged(_state);
+       if (_current == -1) {
+               _current = 0;
+               _track = _playlist.tracks().at(0);
+               _set_source();
+       }
+       _player->play();
 }
 
 void Player::enqueue(int id) {