~ari-tczew/ubuntu/natty/clementine/lp-747113

« back to all changes in this revision

Viewing changes to src/engines/phononengine.cpp

  • Committer: Artur Rona
  • Date: 2011-04-04 20:05:33 UTC
  • Revision ID: ari-tczew@ubuntu.com-20110404200533-6aclzasj5pp8t1hq
* New upstream release. (LP: #747113)
* Drop all patches, have been applied upstream.
* Update debian/copyright.
* Refresh description in debian/control in order to avoid lintian error.
* Bump debhelper to 8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
4
 
   Clementine is free software: you can redistribute it and/or modify
5
 
   it under the terms of the GNU General Public License as published by
6
 
   the Free Software Foundation, either version 3 of the License, or
7
 
   (at your option) any later version.
8
 
 
9
 
   Clementine is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
   GNU General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU General Public License
15
 
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16
 
*/
17
 
 
18
 
#include "phononengine.h"
19
 
 
20
 
#include <QTimer>
21
 
 
22
 
PhononEngine::PhononEngine()
23
 
  : media_object_(new Phonon::MediaObject(this)),
24
 
    audio_output_(new Phonon::AudioOutput(Phonon::MusicCategory, this)),
25
 
    state_timer_(new QTimer(this)),
26
 
    seek_offset_(-1)
27
 
{
28
 
  Phonon::createPath(media_object_, audio_output_);
29
 
 
30
 
  connect(media_object_, SIGNAL(finished()), SLOT(PhononFinished()));
31
 
  connect(media_object_, SIGNAL(stateChanged(Phonon::State,Phonon::State)), SLOT(PhononStateChanged(Phonon::State)));
32
 
 
33
 
  state_timer_->setSingleShot(true);
34
 
  connect(state_timer_, SIGNAL(timeout()), SLOT(StateTimeoutExpired()));
35
 
}
36
 
 
37
 
PhononEngine::~PhononEngine() {
38
 
  delete media_object_;
39
 
  delete audio_output_;
40
 
}
41
 
 
42
 
bool PhononEngine::Init() {
43
 
  return true;
44
 
}
45
 
 
46
 
bool PhononEngine::CanDecode(const QUrl &url) {
47
 
  // TODO
48
 
  return true;
49
 
}
50
 
 
51
 
bool PhononEngine::Load(const QUrl &url, Engine::TrackChangeType change ) {
52
 
  media_object_->setCurrentSource(Phonon::MediaSource(url));
53
 
  return true;
54
 
}
55
 
 
56
 
bool PhononEngine::Play(uint offset) {
57
 
  // The seek happens in PhononStateChanged - phonon doesn't seem to change
58
 
  // currentTime() if we seek before we start playing :S
59
 
  seek_offset_ = offset;
60
 
 
61
 
  media_object_->play();
62
 
  return true;
63
 
}
64
 
 
65
 
void PhononEngine::Stop() {
66
 
  media_object_->stop();
67
 
}
68
 
 
69
 
void PhononEngine::Pause() {
70
 
  media_object_->pause();
71
 
}
72
 
 
73
 
void PhononEngine::Unpause() {
74
 
  media_object_->play();
75
 
}
76
 
 
77
 
Engine::State PhononEngine::state() const {
78
 
  switch (media_object_->state()) {
79
 
    case Phonon::LoadingState:
80
 
    case Phonon::PlayingState:
81
 
    case Phonon::BufferingState:
82
 
      return Engine::Playing;
83
 
 
84
 
    case Phonon::PausedState:
85
 
      return Engine::Paused;
86
 
 
87
 
    case Phonon::StoppedState:
88
 
    case Phonon::ErrorState:
89
 
    default:
90
 
      return Engine::Empty;
91
 
  }
92
 
}
93
 
 
94
 
uint PhononEngine::position() const {
95
 
  return media_object_->currentTime();
96
 
}
97
 
 
98
 
uint PhononEngine::length() const {
99
 
  return media_object_->totalTime();
100
 
}
101
 
 
102
 
void PhononEngine::Seek(uint ms) {
103
 
  media_object_->seek(ms);
104
 
}
105
 
 
106
 
void PhononEngine::SetVolumeSW(uint volume) {
107
 
  audio_output_->setVolume(volume);
108
 
}
109
 
 
110
 
void PhononEngine::PhononFinished() {
111
 
  emit TrackEnded();
112
 
}
113
 
 
114
 
void PhononEngine::PhononStateChanged(Phonon::State new_state) {
115
 
  if (new_state == Phonon::ErrorState) {
116
 
    emit Error(media_object_->errorString());
117
 
  }
118
 
  if (new_state == Phonon::PlayingState && seek_offset_ != -1) {
119
 
    media_object_->seek(seek_offset_);
120
 
    seek_offset_ = -1;
121
 
  }
122
 
 
123
 
  // Don't emit the state change straight away
124
 
  state_timer_->start(100);
125
 
}
126
 
 
127
 
void PhononEngine::StateTimeoutExpired() {
128
 
  emit StateChanged(state());
129
 
}