added pause/stop functionality to Scratchpad

This commit is contained in:
fgerlits 2005-03-16 20:01:48 +00:00
parent 162ea44857
commit d793343c37
11 changed files with 290 additions and 51 deletions

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h,v $
------------------------------------------------------------------------------*/
@ -68,7 +68,7 @@ using namespace LiveSupport::Core;
* A generic interface for playing audio files.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class AudioPlayerInterface
{
@ -135,18 +135,31 @@ class AudioPlayerInterface
/**
* Start playing.
* This call will start playing the active playlist, which was
* set by a previous call to playThis().
* set by a previous call to open().
* Playing can be stopped by calling stop().
*
* @exception std::logic_error if there was no previous call to
* playThis().
* @see #playThis
* @see #open
* @see #stop
*/
virtual void
start(void) throw (std::logic_error)
= 0;
/**
* Pause the player.
* Playing can be resumed by calling start().
*
* @exception std::logic_error if there was no previous call to
* open().
* @see #open
* @see #start
*/
virtual void
pause(void) throw (std::logic_error)
= 0;
/**
* Tell if we're currently playing.
*

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/AudioPlayerFactoryTest.cxx,v $
------------------------------------------------------------------------------*/
@ -147,7 +147,7 @@ AudioPlayerFactoryTest :: simplePlayTest(void)
{
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
Ptr<AudioPlayerInterface>::Ref audioPlayer;
Ptr<time_duration>::Ref sleepT(new time_duration(microseconds(10)));
Ptr<time_duration>::Ref sleepT;
audioPlayerFactory = AudioPlayerFactory::getInstance();
audioPlayer = audioPlayerFactory->getAudioPlayer();
@ -160,6 +160,15 @@ AudioPlayerFactoryTest :: simplePlayTest(void)
CPPUNIT_ASSERT(!audioPlayer->isPlaying());
audioPlayer->start();
CPPUNIT_ASSERT(audioPlayer->isPlaying());
sleepT.reset(new time_duration(seconds(8)));
TimeConversion::sleep(sleepT);
audioPlayer->pause();
sleepT.reset(new time_duration(seconds(1)));
TimeConversion::sleep(sleepT);
audioPlayer->start();
sleepT.reset(new time_duration(microseconds(10)));
while (audioPlayer->isPlaying()) {
TimeConversion::sleep(sleepT);
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.16 $
Version : $Revision: 1.17 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.cxx,v $
------------------------------------------------------------------------------*/
@ -329,6 +329,20 @@ HelixPlayer :: start(void) throw (std::logic_error)
}
/*------------------------------------------------------------------------------
* Pause the player
*----------------------------------------------------------------------------*/
void
HelixPlayer :: pause(void) throw (std::logic_error)
{
if (player->GetSourceCount() == 0) {
throw std::logic_error("HelixPlayer::open() not called yet");
}
player->Pause();
playing = false; // Is this what we want?
}
/*------------------------------------------------------------------------------
* Tell if we're playing
*----------------------------------------------------------------------------*/

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.14 $
Version : $Revision: 1.15 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.h,v $
------------------------------------------------------------------------------*/
@ -112,7 +112,7 @@ using namespace LiveSupport::Core;
* </pre></code>
*
* @author $Author: fgerlits $
* @version $Revision: 1.14 $
* @version $Revision: 1.15 $
*/
class HelixPlayer : virtual public Configurable,
virtual public AudioPlayerInterface,
@ -338,6 +338,18 @@ class HelixPlayer : virtual public Configurable,
virtual void
start(void) throw (std::logic_error);
/**
* Pause the player.
* Playing can be resumed by calling start().
*
* @exception std::logic_error if there was no previous call to
* open().
* @see #open
* @see #start
*/
virtual void
pause(void) throw (std::logic_error);
/**
* Tell if we're currently playing.
*

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.8 $
Version : $Revision: 1.9 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/DjBagWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -70,6 +70,10 @@ DjBagWindow :: DjBagWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
set_title(*getResourceUstring("windowTitle"));
playButton.reset(new Gtk::Button(
*getResourceUstring("playButtonLabel")));
pauseButton.reset(new Gtk::Button(
*getResourceUstring("pauseButtonLabel")));
stopButton.reset(new Gtk::Button(
*getResourceUstring("stopButtonLabel")));
closeButton.reset(new Gtk::Button(
*getResourceUstring("closeButtonLabel")));
} catch (std::invalid_argument &e) {
@ -82,7 +86,23 @@ DjBagWindow :: DjBagWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
playButton->set_relief(Gtk::RELIEF_NORMAL);
// Register the signal handler for the button getting clicked.
playButton->signal_clicked().connect(sigc::mem_fun(*this,
&DjBagWindow::onPlayItem));
&DjBagWindow::onPlayButtonClicked));
// set up the pause button
pauseButton->set_name("pauseButton");
pauseButton->set_flags(Gtk::CAN_FOCUS|Gtk::CAN_DEFAULT|Gtk::HAS_DEFAULT);
pauseButton->set_relief(Gtk::RELIEF_NORMAL);
// Register the signal handler for the button getting clicked.
pauseButton->signal_clicked().connect(sigc::mem_fun(*this,
&DjBagWindow::onPauseButtonClicked));
// set up the stop button
stopButton->set_name("stopButton");
stopButton->set_flags(Gtk::CAN_FOCUS|Gtk::CAN_DEFAULT|Gtk::HAS_DEFAULT);
stopButton->set_relief(Gtk::RELIEF_NORMAL);
// Register the signal handler for the button getting clicked.
stopButton->signal_clicked().connect(sigc::mem_fun(*this,
&DjBagWindow::onStopButtonClicked));
// set up the close button
closeButton->set_name("closeButton");
@ -111,6 +131,14 @@ DjBagWindow :: DjBagWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
playButtonBox.set_border_width(5);
playButtonBox.set_layout(Gtk::BUTTONBOX_SPREAD);
playButtonBox.pack_start(*pauseButton, Gtk::PACK_SHRINK);
playButtonBox.set_border_width(5);
playButtonBox.set_layout(Gtk::BUTTONBOX_SPREAD);
playButtonBox.pack_start(*stopButton, Gtk::PACK_SHRINK);
playButtonBox.set_border_width(5);
playButtonBox.set_layout(Gtk::BUTTONBOX_SPREAD);
buttonBox.pack_start(*closeButton, Gtk::PACK_SHRINK);
buttonBox.set_border_width(5);
buttonBox.set_layout(Gtk::BUTTONBOX_END);
@ -555,8 +583,59 @@ DjBagWindow :: onPlayItem(void) throw ()
if (iter) {
Ptr<Playable>::Ref playable = (*iter)[modelColumns.playableColumn];
gLiveSupport->play(playable);
try {
gLiveSupport->playAudio(playable);
} catch (XmlRpcException &e) {
std::cerr << "GLiveSupport::playAudio() error:" << std::endl
<< e.what() << std::endl;
} catch (std::exception &e) {
std::cerr << "GLiveSupport::playAudio() error:" << std::endl
<< e.what() << std::endl;
}
}
}
}
/*------------------------------------------------------------------------------
* Event handler for the Play button getting clicked
*----------------------------------------------------------------------------*/
void
DjBagWindow :: onPlayButtonClicked(void) throw ()
{
onPlayItem();
}
/*------------------------------------------------------------------------------
* Event handler for the Pause button getting clicked
*----------------------------------------------------------------------------*/
void
DjBagWindow :: onPauseButtonClicked(void) throw ()
{
try {
gLiveSupport->pauseAudio();
} catch (std::logic_error &e) {
std::cerr << "GLiveSupport::pauseAudio() error:" << std::endl
<< e.what() << std::endl;
}
}
/*------------------------------------------------------------------------------
* Event handler for the Stop button getting clicked
*----------------------------------------------------------------------------*/
void
DjBagWindow :: onStopButtonClicked(void) throw ()
{
try {
gLiveSupport->stopAudio();
} catch (XmlRpcException &e) {
std::cerr << "GLiveSupport::stopAudio() error:" << std::endl
<< e.what() << std::endl;
} catch (std::logic_error &e) {
std::cerr << "GLiveSupport::stopAudio() error:" << std::endl
<< e.what() << std::endl;
}
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.6 $
Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/Attic/DjBagWindow.h,v $
------------------------------------------------------------------------------*/
@ -68,7 +68,7 @@ using namespace LiveSupport::Core;
* playlists.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class DjBagWindow : public Gtk::Window, public LocalizedObject
{
@ -80,7 +80,7 @@ class DjBagWindow : public Gtk::Window, public LocalizedObject
* Lists one clip per row.
*
* @author $Author: fgerlits $
* @version $Revision: 1.6 $
* @version $Revision: 1.7 $
*/
class ModelColumns : public Gtk::TreeModel::ColumnRecord
{
@ -152,6 +152,16 @@ class DjBagWindow : public Gtk::Window, public LocalizedObject
*/
Ptr<Gtk::Button>::Ref playButton;
/**
* The pause button.
*/
Ptr<Gtk::Button>::Ref pauseButton;
/**
* The stop button.
*/
Ptr<Gtk::Button>::Ref stopButton;
/**
* The box containing the close button.
*/
@ -174,6 +184,24 @@ class DjBagWindow : public Gtk::Window, public LocalizedObject
*/
Ptr<Gtk::Menu>::Ref playlistMenu;
/**
* Signal handler for the play button clicked.
*/
virtual void
onPlayButtonClicked(void) throw ();
/**
* Signal handler for the pause button clicked.
*/
virtual void
onPauseButtonClicked(void) throw ();
/**
* Signal handler for the stop button clicked.
*/
virtual void
onStopButtonClicked(void) throw ();
/**
* Signal handler for the close button clicked.
*/

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.22 $
Version : $Revision: 1.23 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.cxx,v $
------------------------------------------------------------------------------*/
@ -477,7 +477,7 @@ GLiveSupport :: addToPlaylist(Ptr<const UniqueId>::Ref id)
openPlaylistForEditing();
}
// for some wierd reason, the storage functions won't accept
// for some weird reason, the storage functions won't accept
// Ptr<const UniqueId>::Ref, just a non-const version
Ptr<UniqueId>::Ref uid(new UniqueId(id->getId()));
@ -572,40 +572,85 @@ GLiveSupport :: deletePlayable(Ptr<Playable>::Ref playable)
*----------------------------------------------------------------------------*/
void
LiveSupport :: GLiveSupport ::
GLiveSupport :: play(Ptr<Playable>::Ref playable)
throw (XmlRpcException,
std::runtime_error)
GLiveSupport :: playAudio(Ptr<Playable>::Ref playable)
throw (XmlRpcException,
std::invalid_argument,
std::logic_error,
std::runtime_error)
{
Ptr<AudioClip>::Ref tempAudioClip;
Ptr<Playlist>::Ref tempPlaylist;
Ptr<time_duration>::Ref sleepT(new time_duration(microseconds(10)));
if (audioPlayerIsPaused) {
audioPlayer->start();
audioPlayerIsPaused = false;
return;
}
stopAudio(); // stop the audio player and release old resources
switch (playable->getType()) {
case Playable::AudioClipType:
tempAudioClip = storage->acquireAudioClip(sessionId,
playable->getId());
audioPlayer->open(*tempAudioClip->getUri());
itemPlayingNow = storage->acquireAudioClip(sessionId,
playable->getId());
audioPlayer->open(*itemPlayingNow->getUri());
audioPlayer->start();
while (audioPlayer->isPlaying()) {
TimeConversion::sleep(sleepT);
}
audioPlayer->close();
storage->releaseAudioClip(sessionId, tempAudioClip);
break;
case Playable::PlaylistType:
tempPlaylist = storage->acquirePlaylist(sessionId,
playable->getId());
audioPlayer->openAndStart(tempPlaylist);
while (audioPlayer->isPlaying()) {
TimeConversion::sleep(sleepT);
}
audioPlayer->close();
storage->releasePlaylist(sessionId, tempPlaylist);
itemPlayingNow = storage->acquirePlaylist(sessionId,
playable->getId());
audioPlayer->openAndStart(itemPlayingNow->getPlaylist());
break;
default:
default: // this never happens
break;
}
audioPlayerIsPaused = false;
}
/*------------------------------------------------------------------------------
* Stop the audio player.
*----------------------------------------------------------------------------*/
void
LiveSupport :: GLiveSupport ::
GLiveSupport :: stopAudio(void)
throw (XmlRpcException,
std::logic_error)
{
audioPlayer->close();
if (itemPlayingNow) {
switch (itemPlayingNow->getType()) {
case Playable::AudioClipType:
storage->releaseAudioClip(sessionId,
itemPlayingNow->getAudioClip());
itemPlayingNow.reset();
break;
case Playable::PlaylistType:
storage->releasePlaylist(sessionId,
itemPlayingNow->getPlaylist());
itemPlayingNow.reset();
break;
default: // this never happens
break;
}
}
audioPlayerIsPaused = false;
}
/*------------------------------------------------------------------------------
* Pause the audio player.
*----------------------------------------------------------------------------*/
void
LiveSupport :: GLiveSupport ::
GLiveSupport :: pauseAudio(void)
throw (std::logic_error)
{
if (audioPlayer->isPlaying()) {
audioPlayer->pause();
audioPlayerIsPaused = true;
}
}

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.21 $
Version : $Revision: 1.22 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/GLiveSupport.h,v $
------------------------------------------------------------------------------*/
@ -100,7 +100,7 @@ class MasterPanelWindow;
* respective documentation.
*
* @author $Author: fgerlits $
* @version $Revision: 1.21 $
* @version $Revision: 1.22 $
* @see LocalizedObject#getBundle(const xmlpp::Element &)
* @see AuthenticationClientFactory
* @see StorageClientFactory
@ -182,6 +182,16 @@ class GLiveSupport : public LocalizedConfigurable,
*/
Ptr<Playlist>::Ref editedPlaylist;
/**
* The playlist or audio clip that is being played (may be null).
*/
Ptr<Playable>::Ref itemPlayingNow;
/**
* True if the audio player has been paused.
*/
bool audioPlayerIsPaused;
/**
* Read a supportedLanguages configuration element,
* and fill the supportedLanguages map with its contents.
@ -511,13 +521,37 @@ class GLiveSupport : public LocalizedConfigurable,
* Play a Playable object using the audio player.
*
* @param playable the Playable object to play.
* @exception XmlRpcException in case of XML-RPC errors.
* @exception XmlRpcException in case of storage server errors.
* @exception std::invalid_argument in case of audio player errors.
* @exception std::logic_error in case of audio player errors.
* @exception std::runtime_error in case of audio player errors.
*/
virtual void
play(Ptr<Playable>::Ref playable)
throw (XmlRpcException,
std::runtime_error);
playAudio(Ptr<Playable>::Ref playable)
throw (XmlRpcException,
std::invalid_argument,
std::logic_error,
std::runtime_error);
/**
* Stop the audio player.
*
* @exception XmlRpcException in case of storage server errors.
* @exception std::logic_error in case of audio player errors.
*/
virtual void
stopAudio(void)
throw (XmlRpcException,
std::logic_error);
/**
* Pause the audio player.
*
* @exception std::logic_error in case of audio player errors.
*/
virtual void
pauseAudio(void)
throw (std::logic_error);
};

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.13 $
Author : $Author: fgerlits $
Version : $Revision: 1.14 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/gLiveSupport/src/MasterPanelWindow.cxx,v $
------------------------------------------------------------------------------*/
@ -177,6 +177,7 @@ MasterPanelWindow :: MasterPanelWindow (Ptr<GLiveSupport>::Ref gLiveSupport,
MasterPanelWindow :: ~MasterPanelWindow (void) throw ()
{
resetTimer();
gLiveSupport->stopAudio();
}

View file

@ -38,8 +38,10 @@ hu:table
typeColumnLabel:string { "típus" }
titleColumnLabel:string { "cím" }
closeButtonLabel:string { "bezár" }
playButtonLabel:string { "lejátszás" }
pauseButtonLabel:string { "szünet" }
stopButtonLabel:string { "stop" }
closeButtonLabel:string { "bezár" }
upMenuItem:string { "_Fel" }
downMenuItem:string { "_Le" }

View file

@ -38,8 +38,10 @@ root:table
typeColumnLabel:string { "type" }
titleColumnLabel:string { "title" }
closeButtonLabel:string { "close" }
playButtonLabel:string { "play" }
pauseButtonLabel:string { "pause" }
stopButtonLabel:string { "stop" }
closeButtonLabel:string { "close" }
upMenuItem:string { "Move _Up" }
downMenuItem:string { "Move D_own" }