summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/mediaplayer.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/mediaplayer.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/mediaplayer.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/mediaplayer.cpp b/core/multimedia/opieplayer/mediaplayer.cpp
new file mode 100644
index 0000000..3d8f76c
--- a/dev/null
+++ b/core/multimedia/opieplayer/mediaplayer.cpp
@@ -0,0 +1,182 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include <qpe/qpeapplication.h>
21#include <qpe/qlibrary.h>
22#include <qpe/resource.h>
23#include <qpe/config.h>
24
25#include <qmainwindow.h>
26#include <qmessagebox.h>
27#include <qwidgetstack.h>
28#include <qfile.h>
29
30#include "mediaplayer.h"
31#include "playlistwidget.h"
32#include "audiowidget.h"
33#include "loopcontrol.h"
34#include "audiodevice.h"
35
36#include "mediaplayerstate.h"
37
38
39extern AudioWidget *audioUI;
40extern PlayListWidget *playList;
41extern LoopControl *loopControl;
42extern MediaPlayerState *mediaPlayerState;
43
44
45MediaPlayer::MediaPlayer( QObject *parent, const char *name )
46 : QObject( parent, name ), volumeDirection( 0 ), currentFile( NULL ) {
47
48 connect( mediaPlayerState, SIGNAL( playingToggled( bool ) ), this, SLOT( setPlaying( bool ) ) );
49 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( pauseCheck( bool ) ) );
50 connect( mediaPlayerState, SIGNAL( next() ), this, SLOT( next() ) );
51 connect( mediaPlayerState, SIGNAL( prev() ), this, SLOT( prev() ) );
52
53 connect( audioUI, SIGNAL( moreClicked() ), this, SLOT( startIncreasingVolume() ) );
54 connect( audioUI, SIGNAL( lessClicked() ), this, SLOT( startDecreasingVolume() ) );
55 connect( audioUI, SIGNAL( moreReleased() ), this, SLOT( stopChangingVolume() ) );
56 connect( audioUI, SIGNAL( lessReleased() ), this, SLOT( stopChangingVolume() ) );
57}
58
59
60MediaPlayer::~MediaPlayer() {
61}
62
63
64void MediaPlayer::pauseCheck( bool b ) {
65 // Only pause if playing
66 if ( b && !mediaPlayerState->playing() )
67 mediaPlayerState->setPaused( FALSE );
68}
69
70
71void MediaPlayer::play() {
72 mediaPlayerState->setPlaying( FALSE );
73 mediaPlayerState->setPlaying( TRUE );
74}
75
76
77void MediaPlayer::setPlaying( bool play ) {
78
79 if ( !play ) {
80 mediaPlayerState->setPaused( FALSE );
81 loopControl->stop( FALSE );
82 return;
83 }
84
85 if ( mediaPlayerState->paused() ) {
86 mediaPlayerState->setPaused( FALSE );
87 return;
88 }
89
90 const DocLnk *playListCurrent = playList->current();
91
92 if ( playListCurrent != NULL ) {
93 loopControl->stop( TRUE );
94 currentFile = playListCurrent;
95 }
96
97 if ( currentFile == NULL ) {
98 QMessageBox::critical( 0, tr( "No file"), tr( "Error: There is no file selected" ) );
99 mediaPlayerState->setPlaying( FALSE );
100 return;
101 }
102
103 if ( !QFile::exists( currentFile->file() ) ) {
104 QMessageBox::critical( 0, tr( "File not found"), tr( "The following file was not found: <i>" ) + currentFile->file() + "</i>" );
105 mediaPlayerState->setPlaying( FALSE );
106 return;
107 }
108
109 if ( !mediaPlayerState->newDecoder( currentFile->file() ) ) {
110 QMessageBox::critical( 0, tr( "No decoder found"), tr( "Sorry, no appropriate decoders found for this file: <i>" ) + currentFile->file() + "</i>" );
111 mediaPlayerState->setPlaying( FALSE );
112 return;
113 }
114
115 if ( !loopControl->init( currentFile->file() ) ) {
116 QMessageBox::critical( 0, tr( "Error opening file"), tr( "Sorry, an error occured trying to play the file: <i>" ) + currentFile->file() + "</i>" );
117 mediaPlayerState->setPlaying( FALSE );
118 return;
119 }
120
121 long seconds = loopControl->totalPlaytime();
122 QString time; time.sprintf("%li:%02i", seconds/60, (int)seconds%60 );
123 QString tickerText = tr( " File: " ) + currentFile->name() + tr(", Length: ") + time;
124 QString fileInfo = mediaPlayerState->curDecoder()->fileInfo();
125 if ( !fileInfo.isEmpty() )
126 tickerText += ", " + fileInfo;
127 audioUI->setTickerText( tickerText + "." );
128
129 loopControl->play();
130
131 mediaPlayerState->setView( loopControl->hasVideo() ? 'v' : 'a' );
132}
133
134
135void MediaPlayer::prev() {
136 if ( playList->prev() )
137 play();
138 else if ( mediaPlayerState->looping() ) {
139 if ( playList->last() )
140 play();
141 } else
142 mediaPlayerState->setList();
143}
144
145
146void MediaPlayer::next() {
147 if ( playList->next() )
148 play();
149 else if ( mediaPlayerState->looping() ) {
150 if ( playList->first() )
151 play();
152 } else
153 mediaPlayerState->setList();
154}
155
156
157void MediaPlayer::startDecreasingVolume() {
158 volumeDirection = -1;
159 startTimer( 100 );
160 AudioDevice::decreaseVolume();
161}
162
163
164void MediaPlayer::startIncreasingVolume() {
165 volumeDirection = +1;
166 startTimer( 100 );
167 AudioDevice::increaseVolume();
168}
169
170
171void MediaPlayer::stopChangingVolume() {
172 killTimers();
173}
174
175
176void MediaPlayer::timerEvent( QTimerEvent * ) {
177 if ( volumeDirection == +1 )
178 AudioDevice::increaseVolume();
179 else if ( volumeDirection == -1 )
180 AudioDevice::decreaseVolume();
181}
182