@@ -22,6 +22,9 @@ Audio::Audio(QObject* parent):
2222 QObject(parent),
2323 m_playbackState(StoppedState)
2424{
25+ qsrand(time(NULL));
26+ m_timer.setInterval(1000);
27+ connect(&m_timer, SIGNAL(timeout()), SLOT(timerEvent()));
2528}
2629
2730QUrl Audio::source() const
@@ -34,6 +37,12 @@ void Audio::setSource(const QUrl &source)
3437 if (m_source != source) {
3538 m_source = source;
3639 Q_EMIT sourceChanged(source);
40+
41+ m_position = 0;
42+ Q_EMIT positionChanged(m_position);
43+
44+ m_duration = (qrand() % 20000) + 10000;
45+ Q_EMIT durationChanged(m_duration);
3746 }
3847}
3948
@@ -42,6 +51,16 @@ Audio::PlaybackState Audio::playbackState() const
4251 return m_playbackState;
4352}
4453
54+int Audio::position() const
55+{
56+ return m_position;
57+}
58+
59+int Audio::duration() const
60+{
61+ return m_duration;
62+}
63+
4564QString Audio::errorString() const
4665{
4766 return QString();
@@ -51,7 +70,8 @@ void Audio::pause()
5170{
5271 if (m_playbackState == PlayingState) {
5372 m_playbackState = PausedState;
54− Q_EMIT playbackStateChanged();
73+ Q_EMIT playbackStateChanged(m_playbackState);
74+ m_timer.stop();
5575 }
5676}
5777
@@ -59,7 +79,9 @@ void Audio::play()
5979{
6080 if (m_playbackState != PlayingState && m_source.isValid()) {
6181 m_playbackState = PlayingState;
62− Q_EMIT playbackStateChanged();
82+ Q_EMIT playbackStateChanged(m_playbackState);
83+
84+ m_timer.start();
6385 }
6486}
6587
@@ -67,6 +89,19 @@ void Audio::stop()
6789{
6890 if (m_playbackState != StoppedState) {
6991 m_playbackState = StoppedState;
70− Q_EMIT playbackStateChanged();
92+ Q_EMIT playbackStateChanged(m_playbackState);
93+ m_timer.stop();
94+ m_position = 0;
95+ Q_EMIT positionChanged(m_position);
96+ }
97+}
98+
99+void Audio::timerEvent()
100+{
101+ if (m_position + 1000 < m_duration) {
102+ m_position += 1000;
103+ Q_EMIT positionChanged(m_position);
104+ } else {
105+ stop();
71106 }
72107}