on dbb8563 help sign in
119 lines 2.6 kB history raw
1/*
2 * Copyright (C) 2013, 2015 Canonical, Ltd.
3 *
4 * This program 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; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Michael Zanetti <michael.zanetti@canonical.com>
17 */
19#include "audio.h"
21Audio::Audio(QObject* parent):
22 QObject(parent),
23 m_playbackState(StoppedState),
24 m_playlist(0)
26 qsrand(time(nullptr));
27 m_timer.setInterval(1000);
28 connect(&m_timer, &QTimer::timeout, this, &Audio::timerEvent);
30 m_position = 0;
31 Q_EMIT positionChanged(m_position);
33 m_duration = (qrand() % 20000) + 10000;
34 Q_EMIT durationChanged(m_duration);
37Audio::PlaybackState Audio::playbackState() const
39 return m_playbackState;
42int Audio::position() const
44 return m_position;
47int Audio::duration() const
49 return m_duration;
52QString Audio::errorString() const
54 return QString();
57void Audio::pause()
59 if (m_playbackState == PlayingState) {
60 m_playbackState = PausedState;
61 Q_EMIT playbackStateChanged(m_playbackState);
62 m_timer.stop();
63 }
66void Audio::play()
68 if (m_playbackState != PlayingState) {
69 m_playbackState = PlayingState;
70 Q_EMIT playbackStateChanged(m_playbackState);
72 m_timer.start();
73 }
76void Audio::stop()
78 if (m_playbackState != StoppedState) {
79 m_playbackState = StoppedState;
80 Q_EMIT playbackStateChanged(m_playbackState);
81 m_timer.stop();
82 m_position = 0;
83 Q_EMIT positionChanged(m_position);
84 }
87void Audio::timerEvent()
89 if (m_position + 1000 < m_duration) {
90 m_position += 1000;
91 Q_EMIT positionChanged(m_position);
92 } else {
93 stop();
94 }
97Audio::AudioRole Audio::audioRole() const
99 return Audio::multimedia;
102void Audio::setAudioRole(Audio::AudioRole audioRole)
104 Q_UNUSED(audioRole);
107DeclarativePlaylist *Audio::playlist() const
109 return m_playlist;
112void Audio::setPlaylist(DeclarativePlaylist *playlist)
114 if (playlist == m_playlist)
115 return;
117 m_playlist = playlist;
118 Q_EMIT playlistChanged();