1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/* This file is part of the KDE project
Copyright (C) 2004 Matthias Kretz <kretz@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "simpleplayer.h"
#include <kurl.h>
#include <kglobal.h>
#include <kinstance.h>
#include <kaboutdata.h>
namespace KDE
{
namespace Multimedia
{
class SimplePlayer::Private
{
public:
Channel * channel;
Player * player;
KURL url;
Player::State state;
float channelvolume;
long time;
TQString title;
TQString type;
};
SimplePlayer::SimplePlayer( TQObject * parent, const char * name )
: TQObject( parent, name )
, d( new Private )
{
connect( Factory::self(), TQT_SIGNAL( deleteYourObjects() ), TQT_SLOT( deleteYourObjects() ) );
connect( Factory::self(), TQT_SIGNAL( recreateObjects() ), TQT_SLOT( recreateObjects() ) );
d->channel = Factory::self()->createChannel( KGlobal::instance()->aboutData()->programName() );
d->player = Factory::self()->createPlayer();
if ( d->player ) {
d->player->setOutputChannel( d->channel );
connect( d->player, TQT_SIGNAL( stateChanged( KDE::Multimedia::Player::State, KDE::Multimedia::Player::State ) ),
TQT_SLOT( stateChanged( KDE::Multimedia::Player::State, KDE::Multimedia::Player::State ) ) );
connect( d->player, TQT_SIGNAL( finished() ), TQT_SIGNAL( finished() ) );
};
}
SimplePlayer::~SimplePlayer()
{
delete d->player;
delete d->channel;
}
void SimplePlayer::play( const KURL & url )
{
if( ! d->player )
return;
if( isPaused() && url == d->url )
{
d->player->play();
return;
}
if( ! d->player->load( url ) )
return;
d->url = url;
if( d->player->state() == Player::Stopped )
d->player->play();
}
void SimplePlayer::pause()
{
if( ! d->player )
return;
d->player->pause();
}
void SimplePlayer::stop()
{
if( ! d->player )
return;
d->player->stop();
}
long SimplePlayer::totalTime() const
{
if( ! d->player )
return 0;
return d->player->totalTime();
}
long SimplePlayer::currentTime() const
{
if( ! d->player )
return 0;
return d->player->currentTime();
}
void SimplePlayer::seek( long ms )
{
if( ! d->player )
return;
d->player->seek( ms );
}
float SimplePlayer::volume() const
{
if( ! d->player )
return 0;
return d->channel->volume();
}
void SimplePlayer::setVolume( float v )
{
if( ! d->player )
return;
d->channel->setVolume( v );
}
bool SimplePlayer::isPlaying() const
{
if( ! d->player )
return false;
return ( d->player->state() == Player::Playing );
}
bool SimplePlayer::isPaused() const
{
if( ! d->player )
return false;
return ( d->player->state() == Player::Paused );
}
void SimplePlayer::stateChanged( Player::State ns, Player::State os )
{
if( ! d->player )
return;
if( os == Player::Loading && ns == Player::Stopped )
d->player->play();
}
void SimplePlayer::deleteYourObjects()
{
d->state = d->player->state();
d->channelvolume = d->channel->volume();
d->time = d->player->currentTime();
d->title = d->channel->channelName();
d->type = d->channel->channelType();
if( d->player )
d->player->stop();
delete d->player;
delete d->channel;
d->player = 0;
d->channel = 0;
}
void SimplePlayer::recreateObjects()
{
d->channel = Factory::self()->createChannel( d->title, d->type );
d->channel->setVolume( d->channelvolume );
d->player = Factory::self()->createPlayer();
if( ! d->player )
return;
d->player->setOutputChannel( d->channel );
if( d->state != Player::NoMedia )
if( ! d->player->load( d->url ) )
return;
if( d->state == Player::Playing || d->state == Player::Paused || d->state == Player::Buffering )
{
d->player->play();
d->player->seek( d->time );
if( d->state == Player::Paused )
d->player->pause();
}
}
}} // namespaces
#include "simpleplayer.moc"
// vim: sw=4 ts=4 noet
|