diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index 804fdcfae7..c1d96da98a 100644 --- a/src/apps/mediaplayer/Controller.cpp +++ b/src/apps/mediaplayer/Controller.cpp @@ -355,8 +355,6 @@ Controller::SetTo(const PlaylistItemRef& item) const media_format& audioTrackFormat = fAudioTrackSupplier->Format(); audioFrameRate = audioTrackFormat.u.raw_audio.frame_rate; audioChannels = audioTrackFormat.u.raw_audio.channel_count; -// if (fVideoTrackSupplier == NULL) -// fVideoFrameRate = audioFrameRate; } if (InitCheck() != B_OK) { @@ -500,6 +498,17 @@ Controller::CurrentAudioTrack() } +int +Controller::AudioTrackChannelCount() +{ + media_format format; + if (GetEncodedAudioFormat(&format) == B_OK) + return format.u.encoded_audio.output.channel_count; + + return 2; +} + + status_t Controller::SelectVideoTrack(int n) { diff --git a/src/apps/mediaplayer/Controller.h b/src/apps/mediaplayer/Controller.h index 0d6b5a5be2..08570f261a 100644 --- a/src/apps/mediaplayer/Controller.h +++ b/src/apps/mediaplayer/Controller.h @@ -98,6 +98,7 @@ public: status_t SelectAudioTrack(int n); int CurrentAudioTrack(); + int AudioTrackChannelCount(); status_t SelectVideoTrack(int n); int CurrentVideoTrack(); diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index d7678996a9..6762bad020 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -101,7 +101,10 @@ enum { M_FILE_DELETE, - M_SHOW_IF_NEEDED + M_SHOW_IF_NEEDED, + + M_SLIDE_CONTROLS, + M_FINISH_SLIDING_CONTROLS }; @@ -162,13 +165,19 @@ MainWin::MainWin(bool isFirstWindow, BMessage* message) fIsFullscreen(false), fAlwaysOnTop(false), fNoInterface(false), + fShowsFullscreenControls(false), fSourceWidth(-1), fSourceHeight(-1), fWidthAspect(0), fHeightAspect(0), fSavedFrame(), fNoVideoFrame(), + fMouseDownTracking(false), + fLastMousePos(0, 0), + fLastMouseMovedTime(system_time()), + fMouseMoveDist(0), + fGlobalSettingsListener(this), fInitialSeekPosition(0) { @@ -376,17 +385,20 @@ MainWin::DispatchMessage(BMessage* msg, BHandler* handler) { if ((msg->what == B_MOUSE_DOWN) && (handler == fBackground || handler == fVideoView - || handler == fControls)) + || handler == fControls)) { _MouseDown(msg, dynamic_cast(handler)); + } if ((msg->what == B_MOUSE_MOVED) && (handler == fBackground || handler == fVideoView - || handler == fControls)) + || handler == fControls)) { _MouseMoved(msg, dynamic_cast(handler)); + } if ((msg->what == B_MOUSE_UP) - && (handler == fBackground || handler == fVideoView)) + && (handler == fBackground || handler == fVideoView)) { _MouseUp(msg); + } if ((msg->what == B_KEY_DOWN) && (handler == fBackground || handler == fVideoView)) { @@ -642,6 +654,7 @@ MainWin::MessageReceived(BMessage* msg) item->SetMarked(i == index); i++; } + _UpdateAudioChannelCount(index); } break; } @@ -838,6 +851,48 @@ MainWin::MessageReceived(BMessage* msg) _ShowIfNeeded(); break; + case M_SLIDE_CONTROLS: + { + float offset; + if (msg->FindFloat("offset", &offset) == B_OK) { + fControls->MoveBy(0, offset); + UpdateIfNeeded(); + snooze(15000); + } + break; + } + case M_FINISH_SLIDING_CONTROLS: + { + float offset; + bool show; + if (msg->FindFloat("offset", &offset) == B_OK + && msg->FindBool("show", &show) == B_OK) { + if (show) + fControls->MoveTo(fControls->Frame().left, offset); + else { + fControls->RemoveSelf(); + fControls->MoveTo(fVideoView->Frame().left, + fVideoView->Frame().bottom + 1); + fBackground->AddChild(fControls); + while (!fControls->IsHidden()) + fControls->Hide(); + } + } + break; + } + case M_HIDE_FULL_SCREEN_CONTROLS: + if (fIsFullscreen) { + BPoint videoViewWhere; + if (msg->FindPoint("where", &videoViewWhere) == B_OK) { + if (!fControls->Frame().Contains(videoViewWhere)) { + _ShowFullscreenControls(false); + // hide the mouse cursor until the user moves it + be_app->ObscureCursor(); + } + } + } + break; + default: if (msg->what >= M_SELECT_AUDIO_TRACK && msg->what <= M_SELECT_AUDIO_TRACK_END) { @@ -1204,6 +1259,7 @@ MainWin::_SetupWindow() // printf("MainWin::_SetupWindow\n"); // Populate the track menus _SetupTrackMenus(fAudioTrackMenu, fVideoTrackMenu); + _UpdateAudioChannelCount(fController->CurrentAudioTrack()); fVideoMenu->SetEnabled(fHasVideo); fAudioMenu->SetEnabled(fHasAudio); @@ -1436,6 +1492,13 @@ MainWin::_SetupTrackMenus(BMenu* audioTrackMenu, BMenu* videoTrackMenu) } +void +MainWin::_UpdateAudioChannelCount(int32 audioTrackIndex) +{ + fControls->SetAudioChannelCount(fController->AudioTrackChannelCount()); +} + + void MainWin::_GetMinimumWindowSize(int& width, int& height) const { @@ -1682,18 +1745,18 @@ MainWin::_MouseMoved(BMessage* msg, BView* originalHandler) BPoint mousePos; uint32 buttons = msg->FindInt32("buttons"); + // On Zeta, only "screen_where" is reliable, "where" + // and "be:view_where" seem to be broken + if (msg->FindPoint("screen_where", &mousePos) != B_OK) { + // TODO: remove + // Workaround for BeOS R5, it has no "screen_where" + if (!originalHandler || msg->FindPoint("where", &mousePos) < B_OK) + return; + originalHandler->ConvertToScreen(&mousePos); + } if (buttons == B_PRIMARY_MOUSE_BUTTON && fMouseDownTracking && !fIsFullscreen) { - // On Zeta, only "screen_where" is reliable, "where" - // and "be:view_where" seem to be broken - if (msg->FindPoint("screen_where", &mousePos) != B_OK) { - // TODO: remove - // Workaround for BeOS R5, it has no "screen_where" - if (!originalHandler || msg->FindPoint("where", &mousePos) < B_OK) - return; - originalHandler->ConvertToScreen(&mousePos); - } // printf("screen where: %.0f, %.0f => ", mousePos.x, mousePos.y); float delta_x = mousePos.x - fMouseDownMousePos.x; float delta_y = mousePos.y - fMouseDownMousePos.y; @@ -1702,6 +1765,25 @@ MainWin::_MouseMoved(BMessage* msg, BView* originalHandler) // printf("move window to %.0f, %.0f\n", x, y); MoveTo(x, y); } + + bigtime_t eventTime; + if (msg->FindInt64("when", &eventTime) != B_OK) + eventTime = system_time(); + + if (buttons == 0 && fIsFullscreen) { + BPoint moveDelta = mousePos - fLastMousePos; + float moveDeltaDist + = sqrtf(moveDelta.x * moveDelta.x + moveDelta.y * moveDelta.y); + if (eventTime - fLastMouseMovedTime < 200000) + fMouseMoveDist += moveDeltaDist; + else + fMouseMoveDist = moveDeltaDist; + if (fMouseMoveDist > 5) + _ShowFullscreenControls(true); + } + + fLastMousePos = mousePos; + fLastMouseMovedTime =eventTime; } @@ -1931,6 +2013,7 @@ MainWin::_ToggleFullscreen() } else { // switch back from full screen mode + _ShowFullscreenControls(false, false); Hide(); MoveTo(fSavedFrame.left, fSavedFrame.top); @@ -2000,6 +2083,54 @@ MainWin::_ShowIfNeeded() } +void +MainWin::_ShowFullscreenControls(bool show, bool animate) +{ + if (fShowsFullscreenControls == show) + return; + + fShowsFullscreenControls = show; + + if (show) { + fControls->RemoveSelf(); + fControls->MoveTo(fVideoView->Bounds().left, + fVideoView->Bounds().bottom + 1); + fVideoView->AddChild(fControls); + while (fControls->IsHidden()) + fControls->Show(); + } + + if (animate) { + // Slide the controls into view. We need to do this with + // messages, otherwise we block the video playback for the + // time of the animation. + const float kAnimationOffsets[] = { 0.05, 0.2, 0.5, 0.2, 0.05 }; + const int32 steps = sizeof(kAnimationOffsets) / sizeof(float); + float moveDist = show ? -fControlsHeight : fControlsHeight; + float originalY = fControls->Frame().top; + for (int32 i = 0; i < steps; i++) { + BMessage message(M_SLIDE_CONTROLS); + message.AddFloat("offset", + floorf(moveDist * kAnimationOffsets[i])); + PostMessage(&message, this); + } + BMessage finalMessage(M_FINISH_SLIDING_CONTROLS); + finalMessage.AddFloat("offset", originalY + moveDist); + finalMessage.AddBool("show", show); + PostMessage(&finalMessage, this); + } else { + if (!show) { + fControls->RemoveSelf(); + fControls->MoveTo(fVideoView->Frame().left, + fVideoView->Frame().bottom + 1); + fBackground->AddChild(fControls); + while (!fControls->IsHidden()) + fControls->Hide(); + } + } +} + + // #pragma mark - diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 870a7a406a..73cf6652d0 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -90,6 +90,7 @@ private: void _SetupVideoAspectItems(BMenu* menu); void _SetupTrackMenus(BMenu* audioTrackMenu, BMenu* videoTrackMenu); + void _UpdateAudioChannelCount(int32 audioTrackIndex); void _GetMinimumWindowSize(int& width, int& height) const; @@ -115,6 +116,8 @@ private: void _ToggleAlwaysOnTop(); void _ToggleNoInterface(); void _ShowIfNeeded(); + void _ShowFullscreenControls(bool show, + bool animate = true); void _SetFileAttributes(); void _UpdateControlsEnabledStatus(); @@ -155,9 +158,12 @@ private: PlaylistObserver* fPlaylistObserver; Controller* fController; ControllerObserver* fControllerObserver; - volatile bool fIsFullscreen; - volatile bool fAlwaysOnTop; - volatile bool fNoInterface; + + bool fIsFullscreen; + bool fAlwaysOnTop; + bool fNoInterface; + bool fShowsFullscreenControls; + int fSourceWidth; int fSourceHeight; int fWidthAspect; @@ -169,9 +175,13 @@ private: int fNoVideoWidth; BRect fSavedFrame; BRect fNoVideoFrame; + bool fMouseDownTracking; BPoint fMouseDownMousePos; BPoint fMouseDownWindowPos; + BPoint fLastMousePos; + bigtime_t fLastMouseMovedTime; + float fMouseMoveDist; ListenerAdapter fGlobalSettingsListener; bool fCloseWhenDonePlayingMovie; diff --git a/src/apps/mediaplayer/VideoView.cpp b/src/apps/mediaplayer/VideoView.cpp index c333edefea..ff0e723eb7 100644 --- a/src/apps/mediaplayer/VideoView.cpp +++ b/src/apps/mediaplayer/VideoView.cpp @@ -100,17 +100,19 @@ VideoView::Pulse() return; bigtime_t now = system_time(); - if (now - fLastMouseMove > 2LL * 1000000) { + if (now - fLastMouseMove > 1500000) { fLastMouseMove = now; // take care of disabling the screen saver BPoint where; uint32 buttons; GetMouse(&where, &buttons, false); if (buttons == 0) { + BMessage message(M_HIDE_FULL_SCREEN_CONTROLS); + message.AddPoint("where", where); + Window()->PostMessage(&message, Window()); + ConvertToScreen(&where); set_mouse_position((int32)where.x, (int32)where.y); - // hide the mouse cursor until the user moves it - be_app->ObscureCursor(); } } } diff --git a/src/apps/mediaplayer/VideoView.h b/src/apps/mediaplayer/VideoView.h index ada37786d1..a5ebc026a8 100644 --- a/src/apps/mediaplayer/VideoView.h +++ b/src/apps/mediaplayer/VideoView.h @@ -12,6 +12,11 @@ #include "VideoTarget.h" +enum { + M_HIDE_FULL_SCREEN_CONTROLS = 'hfsc' +}; + + class VideoView : public BView, public VideoTarget { public: VideoView(BRect frame, const char* name,