* 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
+57 -33
View File
@@ -36,6 +36,7 @@
#include "AutoDeleter.h"
#include "ControllerView.h"
#include "PlaybackState.h"
#include "Settings.h"
#include "VideoView.h"
// suppliers
@@ -81,40 +82,44 @@ void Controller::Listener::MutedChanged(bool) {}
Controller::Controller()
: NodeManager(),
fVideoView(NULL),
fVolume(1.0),
fMuted(false),
: NodeManager(),
fVideoView(NULL),
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),
fRef(),
fMediaFile(NULL),
fRef(),
fMediaFile(NULL),
fVideoSupplier(new ProxyVideoSupplier()),
fAudioSupplier(new ProxyAudioSupplier(this)),
fVideoTrackSupplier(NULL),
fAudioTrackSupplier(NULL),
fVideoSupplier(new ProxyVideoSupplier()),
fAudioSupplier(new ProxyAudioSupplier(this)),
fVideoTrackSupplier(NULL),
fAudioTrackSupplier(NULL),
fAudioTrackList(4),
fVideoTrackList(2),
fAudioTrackList(4),
fVideoTrackList(2),
fPosition(0),
fDuration(0),
fVideoFrameRate(25.0),
fSeekFrame(-1),
fLastSeekEventTime(LONGLONG_MIN),
fPosition(0),
fDuration(0),
fVideoFrameRate(25.0),
fSeekFrame(-1),
fLastSeekEventTime(LONGLONG_MIN),
fAutoplay(true),
fPauseAtEndOfStream(false),
fSeekToStartAfterPause(false),
fGlobalSettingsListener(this),
fListeners(4)
fListeners(4)
{
fStopped = fAutoplay ? false : true;
Settings::Default()->AddListener(&fGlobalSettingsListener);
_AdoptGlobalSettings();
}
Controller::~Controller()
{
Settings::Default()->RemoveListener(&fGlobalSettingsListener);
if (fMediaFile)
fMediaFile->ReleaseAllTracks();
delete fMediaFile;
@@ -124,6 +129,22 @@ Controller::~Controller()
// #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
Controller::Duration()
{
@@ -195,8 +216,6 @@ Controller::SetTo(const entry_ref &ref)
fVideoTrackSupplier = NULL;
fAudioTrackSupplier = NULL;
fPauseAtEndOfStream = false;
fSeekToStartAfterPause = false;
fDuration = 0;
fVideoFrameRate = 25.0;
@@ -452,12 +471,6 @@ Controller::Play()
BAutolock _(this);
if (fSeekToStartAfterPause) {
printf("seeking to start after pause\n");
SetPosition(0);
fSeekToStartAfterPause = false;
}
StartPlaying();
}
@@ -588,9 +601,6 @@ Controller::SetPosition(float value)
fLastSeekEventTime = system_time();
} else
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
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
Controller::_PlaybackState(int32 playingMode) const
{
+9 -4
View File
@@ -29,6 +29,7 @@
#include <Locker.h>
#include <String.h>
#include "ListenerAdapter.h"
#include "NodeManager.h"
class AudioTrackSupplier;
@@ -68,6 +69,7 @@ public:
virtual ~Controller();
// PlaybackManager interface
virtual void MessageReceived(BMessage* message);
virtual int64 Duration();
// NodeManager interface
@@ -125,6 +127,8 @@ public:
void RemoveListener(Listener* listener);
private:
void _AdoptGlobalSettings();
uint32 _PlaybackState(int32 playingMode) const;
void _NotifyFileChanged() const;
@@ -155,9 +159,8 @@ private:
VideoView* fVideoView;
volatile bool fPaused;
volatile bool fStopped;
float fVolume;
float fActiveVolume;
bool fMuted;
entry_ref fRef;
@@ -177,9 +180,11 @@ private:
mutable int32 fSeekFrame;
bigtime_t fLastSeekEventTime;
ListenerAdapter fGlobalSettingsListener;
bool fAutoplay;
volatile bool fPauseAtEndOfStream;
volatile bool fSeekToStartAfterPause;
bool fLoopMovies;
bool fLoopSounds;
uint32 fBackgroundMovieVolumeMode;
BList fListeners;
};
+65 -28
View File
@@ -47,6 +47,7 @@
#include "PeakView.h"
#include "PlaylistObserver.h"
#include "PlaylistWindow.h"
#include "Settings.h"
#include "SettingsWindow.h"
#define NAME "MediaPlayer"
@@ -100,33 +101,34 @@ enum {
MainWin::MainWin()
: BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */)
, fFilePanel(NULL)
, fInfoWin(NULL)
, fPlaylistWindow(NULL)
, fSettingsWindow(NULL)
, fHasFile(false)
, fHasVideo(false)
, fHasAudio(false)
, fPlaylist(new Playlist)
, fPlaylistObserver(new PlaylistObserver(this))
, fController(new Controller)
, fControllerObserver(new ControllerObserver(this,
OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES
| OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES
| OBSERVE_VOLUME_CHANGES))
, fIsFullscreen(false)
, fKeepAspectRatio(true)
, fAlwaysOnTop(false)
, fNoMenu(false)
, fNoBorder(false)
, fNoControls(false)
, fSourceWidth(-1)
, fSourceHeight(-1)
, fWidthScale(1.0)
, fHeightScale(1.0)
, fMouseDownTracking(false)
: BWindow(BRect(100,100,400,300), NAME, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS /* | B_WILL_ACCEPT_FIRST_CLICK */),
fFilePanel(NULL),
fInfoWin(NULL),
fPlaylistWindow(NULL),
fSettingsWindow(NULL),
fHasFile(false),
fHasVideo(false),
fHasAudio(false),
fPlaylist(new Playlist),
fPlaylistObserver(new PlaylistObserver(this)),
fController(new Controller),
fControllerObserver(new ControllerObserver(this,
OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES
| OBSERVE_PLAYBACK_STATE_CHANGES | OBSERVE_POSITION_CHANGES
| OBSERVE_VOLUME_CHANGES)),
fIsFullscreen(false),
fKeepAspectRatio(true),
fAlwaysOnTop(false),
fNoMenu(false),
fNoBorder(false),
fNoControls(false),
fSourceWidth(-1),
fSourceHeight(-1),
fWidthScale(1.0),
fHeightScale(1.0),
fMouseDownTracking(false),
fGlobalSettingsListener(this)
{
static int pos = 0;
MoveBy(pos * 25, pos * 25);
@@ -196,6 +198,9 @@ MainWin::MainWin()
// this makes sure the window thread is running without
// showing the window just yet
Settings::Default()->AddListener(&fGlobalSettingsListener);
_AdoptGlobalSettings();
Show();
}
@@ -369,10 +374,12 @@ MainWin::MessageReceived(BMessage *msg)
break;
case M_MEDIA_SERVER_STARTED:
printf("TODO: implement M_MEDIA_SERVER_STARTED\n");
// fController->...
break;
case M_MEDIA_SERVER_QUIT:
printf("TODO: implement M_MEDIA_SERVER_QUIT\n");
// fController->...
break;
@@ -411,8 +418,20 @@ MainWin::MessageReceived(BMessage *msg)
// ControllerObserver messages
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;
}
case MSG_CONTROLLER_FILE_CHANGED:
// TODO: move all other GUI changes as a reaction to this
// notification
@@ -658,6 +677,13 @@ MainWin::MessageReceived(BMessage *msg)
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:
// let BWindow handle the rest
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;
}
+10 -2
View File
@@ -26,11 +26,13 @@
#include <Button.h>
#include <Slider.h>
#include <FilePanel.h>
#include "Controller.h"
#include "ControllerView.h"
#include "InfoWin.h"
#include "VideoView.h"
#include "ListenerAdapter.h"
#include "Playlist.h"
#include "VideoView.h"
class ControllerObserver;
class PlaylistObserver;
@@ -94,7 +96,9 @@ private:
void _RemovePlaylistItem(int32 index);
void _MarkPlaylistItem(int32 index);
void _MarkSettingsItem(uint32 command, bool mark);
void _AdoptGlobalSettings();
BMenuBar* fMenuBar;
BView* fBackground;
VideoView* fVideoView;
@@ -139,6 +143,10 @@ private:
bool fMouseDownTracking;
BPoint fMouseDownMousePos;
BPoint fMouseDownWindowPos;
ListenerAdapter fGlobalSettingsListener;
bool fCloseWhenDonePlayingMovie;
bool fCloseWhenDonePlayingSound;
};
#endif // __MAIN_WIN_H
+9 -2
View File
@@ -266,14 +266,21 @@ Playlist::GetRefAt(int32 index, entry_ref* _ref) const
// #pragma mark - navigation
void
bool
Playlist::SetCurrentRefIndex(int32 index)
{
bool result = true;
if (index >= CountItems() || index < 0) {
index = -1;
result = false;
}
if (index == fCurrentIndex)
return;
return result;
fCurrentIndex = index;
_NotifyCurrentRefChanged(fCurrentIndex);
return result;
}
+1 -1
View File
@@ -72,7 +72,7 @@ public:
// bool HasRef(const entry_ref& ref) const;
// navigating current ref
void SetCurrentRefIndex(int32 index);
bool SetCurrentRefIndex(int32 index);
int32 CurrentRefIndex() const;
void GetSkipInfo(bool* canSkipPrevious,
@@ -250,10 +250,6 @@ SettingsWindow::SettingsWindow(BRect frame)
#endif
// disable currently unsupported features
fAutostartCB->SetEnabled(false);
fCloseWindowMoviesCB->SetEnabled(false);
fCloseWindowSoundsCB->SetEnabled(false);
fLoopMoviesCB->SetEnabled(false);
fLoopSoundsCB->SetEnabled(false);