* Implemented the "Auto start playback", "Close when done playing movie" and

"Close when done playing sound" settings.
* Removed unused member variables from Controller
* Changed Playlist::SetCurrentRef() to indicate success and prevent the
  current index from getting out of range.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27208 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-08-26 13:45:55 +00:00
parent 139f143c62
commit 9a5f768b19
7 changed files with 151 additions and 74 deletions
+39 -15
View File
@@ -36,6 +36,7 @@
#include "AutoDeleter.h" #include "AutoDeleter.h"
#include "ControllerView.h" #include "ControllerView.h"
#include "PlaybackState.h" #include "PlaybackState.h"
#include "Settings.h"
#include "VideoView.h" #include "VideoView.h"
// suppliers // suppliers
@@ -84,6 +85,9 @@ Controller::Controller()
: NodeManager(), : NodeManager(),
fVideoView(NULL), fVideoView(NULL),
fVolume(1.0), fVolume(1.0),
fActiveVolume(1.0),
// TODO: Implement background volume for inactive players,
// but use only if there are multiple players running at all!
fMuted(false), fMuted(false),
fRef(), fRef(),
@@ -103,18 +107,19 @@ Controller::Controller()
fSeekFrame(-1), fSeekFrame(-1),
fLastSeekEventTime(LONGLONG_MIN), fLastSeekEventTime(LONGLONG_MIN),
fAutoplay(true), fGlobalSettingsListener(this),
fPauseAtEndOfStream(false),
fSeekToStartAfterPause(false),
fListeners(4) fListeners(4)
{ {
fStopped = fAutoplay ? false : true; Settings::Default()->AddListener(&fGlobalSettingsListener);
_AdoptGlobalSettings();
} }
Controller::~Controller() Controller::~Controller()
{ {
Settings::Default()->RemoveListener(&fGlobalSettingsListener);
if (fMediaFile) if (fMediaFile)
fMediaFile->ReleaseAllTracks(); fMediaFile->ReleaseAllTracks();
delete fMediaFile; delete fMediaFile;
@@ -124,6 +129,22 @@ Controller::~Controller()
// #pragma mark - NodeManager interface // #pragma mark - NodeManager interface
void
Controller::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_OBJECT_CHANGED:
// received from fGlobalSettingsListener
// TODO: find out which object, if we ever watch more than
// the global settings instance...
_AdoptGlobalSettings();
break;
default:
NodeManager::MessageReceived(message);
}
}
int64 int64
Controller::Duration() Controller::Duration()
{ {
@@ -195,8 +216,6 @@ Controller::SetTo(const entry_ref &ref)
fVideoTrackSupplier = NULL; fVideoTrackSupplier = NULL;
fAudioTrackSupplier = NULL; fAudioTrackSupplier = NULL;
fPauseAtEndOfStream = false;
fSeekToStartAfterPause = false;
fDuration = 0; fDuration = 0;
fVideoFrameRate = 25.0; fVideoFrameRate = 25.0;
@@ -452,12 +471,6 @@ Controller::Play()
BAutolock _(this); BAutolock _(this);
if (fSeekToStartAfterPause) {
printf("seeking to start after pause\n");
SetPosition(0);
fSeekToStartAfterPause = false;
}
StartPlaying(); StartPlaying();
} }
@@ -588,9 +601,6 @@ Controller::SetPosition(float value)
fLastSeekEventTime = system_time(); fLastSeekEventTime = system_time();
} else } else
fSeekFrame = -1; fSeekFrame = -1;
// TODO: What was this used for in the old framework?
fSeekToStartAfterPause = false;
} }
@@ -741,6 +751,20 @@ Controller::RemoveListener(Listener* listener)
// #pragma mark - Private // #pragma mark - Private
void
Controller::_AdoptGlobalSettings()
{
mpSettings settings = Settings::CurrentSettings();
// thread safe
fAutoplay = settings.autostart;
// not yet used:
fLoopMovies = settings.loopMovie;
fLoopSounds = settings.loopSound;
fBackgroundMovieVolumeMode = settings.backgroundMovieVolumeMode;
}
uint32 uint32
Controller::_PlaybackState(int32 playingMode) const Controller::_PlaybackState(int32 playingMode) const
{ {
+9 -4
View File
@@ -29,6 +29,7 @@
#include <Locker.h> #include <Locker.h>
#include <String.h> #include <String.h>
#include "ListenerAdapter.h"
#include "NodeManager.h" #include "NodeManager.h"
class AudioTrackSupplier; class AudioTrackSupplier;
@@ -68,6 +69,7 @@ public:
virtual ~Controller(); virtual ~Controller();
// PlaybackManager interface // PlaybackManager interface
virtual void MessageReceived(BMessage* message);
virtual int64 Duration(); virtual int64 Duration();
// NodeManager interface // NodeManager interface
@@ -125,6 +127,8 @@ public:
void RemoveListener(Listener* listener); void RemoveListener(Listener* listener);
private: private:
void _AdoptGlobalSettings();
uint32 _PlaybackState(int32 playingMode) const; uint32 _PlaybackState(int32 playingMode) const;
void _NotifyFileChanged() const; void _NotifyFileChanged() const;
@@ -155,9 +159,8 @@ private:
VideoView* fVideoView; VideoView* fVideoView;
volatile bool fPaused;
volatile bool fStopped;
float fVolume; float fVolume;
float fActiveVolume;
bool fMuted; bool fMuted;
entry_ref fRef; entry_ref fRef;
@@ -177,9 +180,11 @@ private:
mutable int32 fSeekFrame; mutable int32 fSeekFrame;
bigtime_t fLastSeekEventTime; bigtime_t fLastSeekEventTime;
ListenerAdapter fGlobalSettingsListener;
bool fAutoplay; bool fAutoplay;
volatile bool fPauseAtEndOfStream; bool fLoopMovies;
volatile bool fSeekToStartAfterPause; bool fLoopSounds;
uint32 fBackgroundMovieVolumeMode;
BList fListeners; BList fListeners;
}; };
+62 -25
View File
@@ -47,6 +47,7 @@
#include "PeakView.h" #include "PeakView.h"
#include "PlaylistObserver.h" #include "PlaylistObserver.h"
#include "PlaylistWindow.h" #include "PlaylistWindow.h"
#include "Settings.h"
#include "SettingsWindow.h" #include "SettingsWindow.h"
#define NAME "MediaPlayer" #define NAME "MediaPlayer"
@@ -101,32 +102,33 @@ enum {
MainWin::MainWin() MainWin::MainWin()
: BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW, : BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */) B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */),
, fFilePanel(NULL) fFilePanel(NULL),
, fInfoWin(NULL) fInfoWin(NULL),
, fPlaylistWindow(NULL) fPlaylistWindow(NULL),
, fSettingsWindow(NULL) fSettingsWindow(NULL),
, fHasFile(false) fHasFile(false),
, fHasVideo(false) fHasVideo(false),
, fHasAudio(false) fHasAudio(false),
, fPlaylist(new Playlist) fPlaylist(new Playlist),
, fPlaylistObserver(new PlaylistObserver(this)) fPlaylistObserver(new PlaylistObserver(this)),
, fController(new Controller) fController(new Controller),
, fControllerObserver(new ControllerObserver(this, fControllerObserver(new ControllerObserver(this,
OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES
| OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES | OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES
| OBSERVE_VOLUME_CHANGES)) | OBSERVE_VOLUME_CHANGES)),
, fIsFullscreen(false) fIsFullscreen(false),
, fKeepAspectRatio(true) fKeepAspectRatio(true),
, fAlwaysOnTop(false) fAlwaysOnTop(false),
, fNoMenu(false) fNoMenu(false),
, fNoBorder(false) fNoBorder(false),
, fNoControls(false) fNoControls(false),
, fSourceWidth(-1) fSourceWidth(-1),
, fSourceHeight(-1) fSourceHeight(-1),
, fWidthScale(1.0) fWidthScale(1.0),
, fHeightScale(1.0) fHeightScale(1.0),
, fMouseDownTracking(false) fMouseDownTracking(false),
fGlobalSettingsListener(this)
{ {
static int pos = 0; static int pos = 0;
MoveBy(pos * 25, pos * 25); MoveBy(pos * 25, pos * 25);
@@ -196,6 +198,9 @@ MainWin::MainWin()
// this makes sure the window thread is running without // this makes sure the window thread is running without
// showing the window just yet // showing the window just yet
Settings::Default()->AddListener(&fGlobalSettingsListener);
_AdoptGlobalSettings();
Show(); Show();
} }
@@ -369,10 +374,12 @@ MainWin::MessageReceived(BMessage *msg)
break; break;
case M_MEDIA_SERVER_STARTED: case M_MEDIA_SERVER_STARTED:
printf("TODO: implement M_MEDIA_SERVER_STARTED\n");
// fController->... // fController->...
break; break;
case M_MEDIA_SERVER_QUIT: case M_MEDIA_SERVER_QUIT:
printf("TODO: implement M_MEDIA_SERVER_QUIT\n");
// fController->... // fController->...
break; break;
@@ -411,8 +418,20 @@ MainWin::MessageReceived(BMessage *msg)
// ControllerObserver messages // ControllerObserver messages
case MSG_CONTROLLER_FILE_FINISHED: case MSG_CONTROLLER_FILE_FINISHED:
fPlaylist->SetCurrentRefIndex(fPlaylist->CurrentRefIndex() + 1); {
bool hadNext = fPlaylist->SetCurrentRefIndex(
fPlaylist->CurrentRefIndex() + 1);
if (!hadNext) {
if (fHasVideo) {
if (fCloseWhenDonePlayingMovie)
PostMessage(B_QUIT_REQUESTED);
} else {
if (fCloseWhenDonePlayingSound)
PostMessage(B_QUIT_REQUESTED);
}
}
break; break;
}
case MSG_CONTROLLER_FILE_CHANGED: case MSG_CONTROLLER_FILE_CHANGED:
// TODO: move all other GUI changes as a reaction to this // TODO: move all other GUI changes as a reaction to this
// notification // notification
@@ -658,6 +677,13 @@ MainWin::MessageReceived(BMessage *msg)
break; break;
} }
case MSG_OBJECT_CHANGED:
// received from fGlobalSettingsListener
// TODO: find out which object, if we ever watch more than
// the global settings instance...
_AdoptGlobalSettings();
break;
default: default:
// let BWindow handle the rest // let BWindow handle the rest
BWindow::MessageReceived(msg); BWindow::MessageReceived(msg);
@@ -1608,3 +1634,14 @@ MainWin::_MarkSettingsItem(uint32 command, bool mark)
} }
void
MainWin::_AdoptGlobalSettings()
{
mpSettings settings = Settings::CurrentSettings();
// thread safe
fCloseWhenDonePlayingMovie = settings.closeWhenDonePlayingMovie;
fCloseWhenDonePlayingSound = settings.closeWhenDonePlayingSound;
}
+9 -1
View File
@@ -26,11 +26,13 @@
#include <Button.h> #include <Button.h>
#include <Slider.h> #include <Slider.h>
#include <FilePanel.h> #include <FilePanel.h>
#include "Controller.h" #include "Controller.h"
#include "ControllerView.h" #include "ControllerView.h"
#include "InfoWin.h" #include "InfoWin.h"
#include "VideoView.h" #include "ListenerAdapter.h"
#include "Playlist.h" #include "Playlist.h"
#include "VideoView.h"
class ControllerObserver; class ControllerObserver;
class PlaylistObserver; class PlaylistObserver;
@@ -95,6 +97,8 @@ private:
void _MarkPlaylistItem(int32 index); void _MarkPlaylistItem(int32 index);
void _MarkSettingsItem(uint32 command, bool mark); void _MarkSettingsItem(uint32 command, bool mark);
void _AdoptGlobalSettings();
BMenuBar* fMenuBar; BMenuBar* fMenuBar;
BView* fBackground; BView* fBackground;
VideoView* fVideoView; VideoView* fVideoView;
@@ -139,6 +143,10 @@ private:
bool fMouseDownTracking; bool fMouseDownTracking;
BPoint fMouseDownMousePos; BPoint fMouseDownMousePos;
BPoint fMouseDownWindowPos; BPoint fMouseDownWindowPos;
ListenerAdapter fGlobalSettingsListener;
bool fCloseWhenDonePlayingMovie;
bool fCloseWhenDonePlayingSound;
}; };
#endif // __MAIN_WIN_H #endif // __MAIN_WIN_H
+9 -2
View File
@@ -266,14 +266,21 @@ Playlist::GetRefAt(int32 index, entry_ref* _ref) const
// #pragma mark - navigation // #pragma mark - navigation
void bool
Playlist::SetCurrentRefIndex(int32 index) Playlist::SetCurrentRefIndex(int32 index)
{ {
bool result = true;
if (index >= CountItems() || index < 0) {
index = -1;
result = false;
}
if (index == fCurrentIndex) if (index == fCurrentIndex)
return; return result;
fCurrentIndex = index; fCurrentIndex = index;
_NotifyCurrentRefChanged(fCurrentIndex); _NotifyCurrentRefChanged(fCurrentIndex);
return result;
} }
+1 -1
View File
@@ -72,7 +72,7 @@ public:
// bool HasRef(const entry_ref& ref) const; // bool HasRef(const entry_ref& ref) const;
// navigating current ref // navigating current ref
void SetCurrentRefIndex(int32 index); bool SetCurrentRefIndex(int32 index);
int32 CurrentRefIndex() const; int32 CurrentRefIndex() const;
void GetSkipInfo(bool* canSkipPrevious, void GetSkipInfo(bool* canSkipPrevious,
@@ -250,10 +250,6 @@ SettingsWindow::SettingsWindow(BRect frame)
#endif #endif
// disable currently unsupported features // disable currently unsupported features
fAutostartCB->SetEnabled(false);
fCloseWindowMoviesCB->SetEnabled(false);
fCloseWindowSoundsCB->SetEnabled(false);
fLoopMoviesCB->SetEnabled(false); fLoopMoviesCB->SetEnabled(false);
fLoopSoundsCB->SetEnabled(false); fLoopSoundsCB->SetEnabled(false);