added playlist support
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17225 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -112,3 +112,26 @@ Controller::Bitmap()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Controller::Stop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Controller::Play()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Controller::Pause()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Controller::IsPaused()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ public:
|
|||||||
|
|
||||||
status_t SetTo(const entry_ref &ref);
|
status_t SetTo(const entry_ref &ref);
|
||||||
|
|
||||||
|
void Stop();
|
||||||
|
void Play();
|
||||||
|
void Pause();
|
||||||
|
bool IsPaused();
|
||||||
|
|
||||||
void SetVideoView(VideoView *view);
|
void SetVideoView(VideoView *view);
|
||||||
|
|
||||||
bool IsOverlayActive();
|
bool IsOverlayActive();
|
||||||
|
|||||||
@@ -22,10 +22,15 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "ControllerView.h"
|
#include "ControllerView.h"
|
||||||
|
#include "Controller.h"
|
||||||
|
#include "Playlist.h"
|
||||||
|
#include "Player.h"
|
||||||
|
|
||||||
ControllerView::ControllerView(BRect frame, Controller *ctrl)
|
ControllerView::ControllerView(BRect frame, Controller *ctrl, Playlist *pl, Player *p)
|
||||||
: TransportControlGroup(frame)
|
: TransportControlGroup(frame)
|
||||||
, fController(ctrl)
|
, fController(ctrl)
|
||||||
|
, fPlaylist(pl)
|
||||||
|
, fPlayer(p)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +77,10 @@ void
|
|||||||
ControllerView::TogglePlaying()
|
ControllerView::TogglePlaying()
|
||||||
{
|
{
|
||||||
printf("ControllerView::TogglePlaying()\n");
|
printf("ControllerView::TogglePlaying()\n");
|
||||||
|
if (fController->IsPaused())
|
||||||
|
fController->Play();
|
||||||
|
else
|
||||||
|
fController->Pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +88,7 @@ void
|
|||||||
ControllerView::Stop()
|
ControllerView::Stop()
|
||||||
{
|
{
|
||||||
printf("ControllerView::Stop()\n");
|
printf("ControllerView::Stop()\n");
|
||||||
|
fController->Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -102,6 +112,11 @@ void
|
|||||||
ControllerView::SkipBackward()
|
ControllerView::SkipBackward()
|
||||||
{
|
{
|
||||||
printf("ControllerView::SkipBackward()\n");
|
printf("ControllerView::SkipBackward()\n");
|
||||||
|
entry_ref ref;
|
||||||
|
if (fPlaylist->PrevRef(&ref) == B_OK) {
|
||||||
|
printf("prev ref: %s\n", ref.name);
|
||||||
|
fPlayer->OpenFile(ref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,6 +124,11 @@ void
|
|||||||
ControllerView::SkipForward()
|
ControllerView::SkipForward()
|
||||||
{
|
{
|
||||||
printf("ControllerView::SkipForward()\n");
|
printf("ControllerView::SkipForward()\n");
|
||||||
|
entry_ref ref;
|
||||||
|
if (fPlaylist->NextRef(&ref) == B_OK) {
|
||||||
|
printf("next ref: %s\n", ref.name);
|
||||||
|
fPlayer->OpenFile(ref);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,11 +25,13 @@
|
|||||||
|
|
||||||
|
|
||||||
class Controller;
|
class Controller;
|
||||||
|
class Playlist;
|
||||||
|
class Player;
|
||||||
|
|
||||||
class ControllerView : public TransportControlGroup
|
class ControllerView : public TransportControlGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControllerView(BRect frame, Controller *ctrl);
|
ControllerView(BRect frame, Controller *ctrl, Playlist *pl, Player *p);
|
||||||
~ControllerView();
|
~ControllerView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -50,6 +52,8 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Controller * fController;
|
Controller * fController;
|
||||||
|
Playlist * fPlaylist;
|
||||||
|
Player * fPlayer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ MainWin::MainWin()
|
|||||||
, fFilePanel(NULL)
|
, fFilePanel(NULL)
|
||||||
, fHasFile(false)
|
, fHasFile(false)
|
||||||
, fHasVideo(false)
|
, fHasVideo(false)
|
||||||
|
, fPlaylist(new Playlist)
|
||||||
, fController(new Controller)
|
, fController(new Controller)
|
||||||
, fIsFullscreen(false)
|
, fIsFullscreen(false)
|
||||||
, fKeepAspectRatio(true)
|
, fKeepAspectRatio(true)
|
||||||
@@ -128,12 +129,12 @@ MainWin::MainWin()
|
|||||||
|
|
||||||
// controls
|
// controls
|
||||||
rect = BRect(0, fMenuBarHeight + 11, fBackground->Bounds().right, fBackground->Bounds().bottom);
|
rect = BRect(0, fMenuBarHeight + 11, fBackground->Bounds().right, fBackground->Bounds().bottom);
|
||||||
fControls = new ControllerView(rect, fController);
|
fControls = new ControllerView(rect, fController, fPlaylist, this);
|
||||||
fBackground->AddChild(fControls);
|
fBackground->AddChild(fControls);
|
||||||
fControls->ResizeToPreferred();
|
fControls->ResizeToPreferred();
|
||||||
fControlsHeight = (int)fControls->Frame().Height() + 1;
|
fControlsHeight = (int)fControls->Frame().Height() + 1;
|
||||||
fControlsWidth = (int)fControls->Frame().Width() + 1;
|
fControlsWidth = (int)fControls->Frame().Width() + 1;
|
||||||
fControls->SetResizingMode(B_FOLLOW_NONE);
|
fControls->SetResizingMode(B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT);
|
||||||
// fControls->MoveTo(0, fBackground->Bounds().bottom - fControlsHeight + 1);
|
// fControls->MoveTo(0, fBackground->Bounds().bottom - fControlsHeight + 1);
|
||||||
|
|
||||||
// fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
|
// fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
|
||||||
@@ -154,6 +155,7 @@ MainWin::MainWin()
|
|||||||
MainWin::~MainWin()
|
MainWin::~MainWin()
|
||||||
{
|
{
|
||||||
printf("MainWin::~MainWin\n");
|
printf("MainWin::~MainWin\n");
|
||||||
|
delete fPlaylist;
|
||||||
delete fController;
|
delete fController;
|
||||||
delete fFilePanel;
|
delete fFilePanel;
|
||||||
}
|
}
|
||||||
@@ -752,25 +754,25 @@ void
|
|||||||
MainWin::RefsReceived(BMessage *msg)
|
MainWin::RefsReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
printf("MainWin::RefsReceived\n");
|
printf("MainWin::RefsReceived\n");
|
||||||
// the first file is played in this window,
|
|
||||||
// if additional files (refs) are included,
|
// the playlist ist replaced by dropped files
|
||||||
// more windows are launched
|
|
||||||
|
fPlaylist->MakeEmpty();
|
||||||
|
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
int n = 0;
|
|
||||||
for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) {
|
for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) {
|
||||||
BEntry entry(&ref, true);
|
BEntry entry(&ref, true);
|
||||||
if (!entry.Exists() || !entry.IsFile())
|
if (!entry.Exists() || !entry.IsFile())
|
||||||
continue;
|
continue;
|
||||||
if (n == 0) {
|
fPlaylist->AddRef(ref);
|
||||||
OpenFile(ref);
|
|
||||||
} else {
|
|
||||||
BMessage m(B_REFS_RECEIVED);
|
|
||||||
m.AddRef("refs", &ref);
|
|
||||||
gMainApp->NewWindow()->PostMessage(&m);
|
|
||||||
}
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fPlaylist->Sort();
|
||||||
|
|
||||||
|
// open first file
|
||||||
|
if (fPlaylist->NextRef(&ref) == B_OK)
|
||||||
|
OpenFile(ref);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,10 @@
|
|||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
#include "ControllerView.h"
|
#include "ControllerView.h"
|
||||||
#include "VideoView.h"
|
#include "VideoView.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "Playlist.h"
|
||||||
|
|
||||||
class MainWin : public BWindow
|
class MainWin : public BWindow, public Player
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MainWin();
|
MainWin();
|
||||||
@@ -48,7 +50,6 @@ public:
|
|||||||
status_t KeyDown(BMessage *msg);
|
status_t KeyDown(BMessage *msg);
|
||||||
|
|
||||||
void CreateMenu();
|
void CreateMenu();
|
||||||
void OpenFile(const entry_ref &ref);
|
|
||||||
void SetupWindow();
|
void SetupWindow();
|
||||||
void SetupTrackMenus();
|
void SetupTrackMenus();
|
||||||
void SetWindowSizeLimits();
|
void SetWindowSizeLimits();
|
||||||
@@ -56,6 +57,9 @@ public:
|
|||||||
void ResizeVideoView(int x, int y, int width, int height);
|
void ResizeVideoView(int x, int y, int width, int height);
|
||||||
|
|
||||||
void ShowFileInfo();
|
void ShowFileInfo();
|
||||||
|
|
||||||
|
// from Player
|
||||||
|
void OpenFile(const entry_ref &ref);
|
||||||
|
|
||||||
void VideoFormatChange(int width, int height, float width_scale, float height_scale);
|
void VideoFormatChange(int width, int height, float width_scale, float height_scale);
|
||||||
|
|
||||||
@@ -85,6 +89,7 @@ public:
|
|||||||
bool fHasFile;
|
bool fHasFile;
|
||||||
bool fHasVideo;
|
bool fHasVideo;
|
||||||
|
|
||||||
|
Playlist * fPlaylist;
|
||||||
Controller * fController;
|
Controller * fController;
|
||||||
volatile bool fIsFullscreen;
|
volatile bool fIsFullscreen;
|
||||||
volatile bool fKeepAspectRatio;
|
volatile bool fKeepAspectRatio;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __PLAYER_H
|
||||||
|
#define __PLAYER_H
|
||||||
|
|
||||||
|
class Player
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void OpenFile(const entry_ref &ref) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Playlist.cpp - Media Player for the Haiku Operating System
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006 Marcus Overhagen <[email protected]>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "Playlist.h"
|
||||||
|
|
||||||
|
// TODO: using BList for objects is bad, replace it with a template
|
||||||
|
|
||||||
|
Playlist::Playlist()
|
||||||
|
: fList()
|
||||||
|
, fCurrentIndex(-1)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Playlist::~Playlist()
|
||||||
|
{
|
||||||
|
MakeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Playlist::MakeEmpty()
|
||||||
|
{
|
||||||
|
int count = fList.CountItems();
|
||||||
|
for (int i = count - 1; i >= 0; i--) {
|
||||||
|
entry_ref *ref = (entry_ref *)fList.RemoveItem(i);
|
||||||
|
delete ref;
|
||||||
|
}
|
||||||
|
fCurrentIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Playlist::CountItems()
|
||||||
|
{
|
||||||
|
return fList.CountItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
Playlist::playlist_cmp(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
return strcmp((*(const entry_ref **)p1)->name, (*(const entry_ref **)p2)->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Playlist::Sort()
|
||||||
|
{
|
||||||
|
fList.SortItems(playlist_cmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Playlist::AddRef(const entry_ref &ref)
|
||||||
|
{
|
||||||
|
fList.AddItem(new entry_ref(ref));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Playlist::NextRef(entry_ref *ref)
|
||||||
|
{
|
||||||
|
int count = fList.CountItems();
|
||||||
|
if (fCurrentIndex + 2 > count)
|
||||||
|
return B_ERROR;
|
||||||
|
*ref = *(entry_ref *)fList.ItemAt(++fCurrentIndex);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Playlist::PrevRef(entry_ref *ref)
|
||||||
|
{
|
||||||
|
int count = fList.CountItems();
|
||||||
|
if (count == 0 || fCurrentIndex <= 0)
|
||||||
|
return B_ERROR;
|
||||||
|
*ref = *(entry_ref *)fList.ItemAt(--fCurrentIndex);
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Playlist.h - Media Player for the Haiku Operating System
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006 Marcus Overhagen <marcus@overhagen.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* version 2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef __PLAYLIST_H
|
||||||
|
#define __PLAYLIST_H
|
||||||
|
|
||||||
|
#include <Entry.h>
|
||||||
|
#include <List.h>
|
||||||
|
|
||||||
|
class Playlist
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Playlist();
|
||||||
|
~Playlist();
|
||||||
|
|
||||||
|
void MakeEmpty();
|
||||||
|
int CountItems();
|
||||||
|
|
||||||
|
void Sort();
|
||||||
|
|
||||||
|
void AddRef(const entry_ref &ref);
|
||||||
|
|
||||||
|
status_t NextRef(entry_ref *ref);
|
||||||
|
status_t PrevRef(entry_ref *ref);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static int playlist_cmp(const void *p1, const void *p2);
|
||||||
|
|
||||||
|
private:
|
||||||
|
BList fList;
|
||||||
|
int fCurrentIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user