Show
Ignore:
Timestamp:
01/07/10 15:35:17 (3 years ago)
Author:
robert
Message:

Added virtual pause() method into osg::AudioSink? to support pausing of a movie thread and it's associated audio.

Updated osgmovie plugin to use the pause support.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp

    r10809 r10925  
    384384 
    385385        SDLAudioSink(osg::AudioStream* audioStream): 
    386             _playing(false), 
     386            _started(false), 
     387            _paused(false), 
    387388            _audioStream(audioStream) {} 
    388389 
    389390        ~SDLAudioSink(); 
    390391 
    391         virtual void startPlaying(); 
    392         virtual bool playing() const { return _playing; } 
    393  
    394  
    395         bool                                _playing; 
     392        virtual void play(); 
     393        virtual void pause(); 
     394        virtual void stop(); 
     395 
     396        virtual bool playing() const { return _started && !_paused; } 
     397 
     398 
     399        bool                                _started; 
     400        bool                                _paused; 
    396401        osg::observer_ptr<osg::AudioStream> _audioStream; 
    397402}; 
     
    671676SDLAudioSink::~SDLAudioSink() 
    672677{ 
    673     if (_playing) 
    674     { 
    675  
    676         SDL_PauseAudio(1); 
    677         SDL_CloseAudio(); 
    678  
    679         osg::notify(osg::NOTICE)<<"~SDLAudioSink() destructor, but still playing"<<std::endl; 
    680     } 
    681 } 
    682  
    683 void SDLAudioSink::startPlaying() 
    684 { 
    685     _playing = true; 
     678    stop(); 
     679} 
     680 
     681void SDLAudioSink::play() 
     682{ 
     683    if (_started) 
     684    { 
     685        if (_paused) 
     686        { 
     687            SDL_PauseAudio(0); 
     688            _paused = false; 
     689        } 
     690        return; 
     691    } 
     692 
     693    _started = true; 
     694    _paused = false; 
     695 
    686696    osg::notify(osg::NOTICE)<<"SDLAudioSink()::startPlaying()"<<std::endl; 
    687697 
     
    708718} 
    709719 
     720void SDLAudioSink::pause() 
     721{ 
     722    if (_started) 
     723    { 
     724        SDL_PauseAudio(1); 
     725        _paused = true; 
     726    } 
     727} 
     728 
     729void SDLAudioSink::stop() 
     730{ 
     731    if (_started) 
     732    { 
     733        if (!_paused) SDL_PauseAudio(1); 
     734        SDL_CloseAudio(); 
     735 
     736        osg::notify(osg::NOTICE)<<"~SDLAudioSink() destructor, but still playing"<<std::endl; 
     737    } 
     738} 
    710739 
    711740#endif