added playlist support

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17225 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marcus Overhagen 2006-04-24 20:47:29 +00:00
parent 5da6291b99
commit aadc5f572d
9 changed files with 234 additions and 18 deletions

View File

@ -112,3 +112,26 @@ Controller::Bitmap()
}
void
Controller::Stop()
{
}
void
Controller::Play()
{
}
void
Controller::Pause()
{
}
bool
Controller::IsPaused()
{
return false;
}

View File

@ -33,6 +33,11 @@ public:
status_t SetTo(const entry_ref &ref);
void Stop();
void Play();
void Pause();
bool IsPaused();
void SetVideoView(VideoView *view);
bool IsOverlayActive();

View File

@ -22,10 +22,15 @@
#include <string.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)
, fController(ctrl)
, fPlaylist(pl)
, fPlayer(p)
{
}
@ -72,6 +77,10 @@ void
ControllerView::TogglePlaying()
{
printf("ControllerView::TogglePlaying()\n");
if (fController->IsPaused())
fController->Play();
else
fController->Pause();
}
@ -79,6 +88,7 @@ void
ControllerView::Stop()
{
printf("ControllerView::Stop()\n");
fController->Stop();
}
@ -102,6 +112,11 @@ void
ControllerView::SkipBackward()
{
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()
{
printf("ControllerView::SkipForward()\n");
entry_ref ref;
if (fPlaylist->NextRef(&ref) == B_OK) {
printf("next ref: %s\n", ref.name);
fPlayer->OpenFile(ref);
}
}

View File

@ -25,11 +25,13 @@
class Controller;
class Playlist;
class Player;
class ControllerView : public TransportControlGroup
{
public:
ControllerView(BRect frame, Controller *ctrl);
ControllerView(BRect frame, Controller *ctrl, Playlist *pl, Player *p);
~ControllerView();
private:
@ -50,6 +52,8 @@ private:
private:
Controller * fController;
Playlist * fPlaylist;
Player * fPlayer;
};
#endif

View File

@ -89,6 +89,7 @@ MainWin::MainWin()
, fFilePanel(NULL)
, fHasFile(false)
, fHasVideo(false)
, fPlaylist(new Playlist)
, fController(new Controller)
, fIsFullscreen(false)
, fKeepAspectRatio(true)
@ -128,12 +129,12 @@ MainWin::MainWin()
// controls
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);
fControls->ResizeToPreferred();
fControlsHeight = (int)fControls->Frame().Height() + 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);
// fVideoView->ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height() - fMenuBarHeight - fControlsHeight);
@ -154,6 +155,7 @@ MainWin::MainWin()
MainWin::~MainWin()
{
printf("MainWin::~MainWin\n");
delete fPlaylist;
delete fController;
delete fFilePanel;
}
@ -752,25 +754,25 @@ void
MainWin::RefsReceived(BMessage *msg)
{
printf("MainWin::RefsReceived\n");
// the first file is played in this window,
// if additional files (refs) are included,
// more windows are launched
// the playlist ist replaced by dropped files
fPlaylist->MakeEmpty();
entry_ref ref;
int n = 0;
for (int i = 0; B_OK == msg->FindRef("refs", i, &ref); i++) {
BEntry entry(&ref, true);
if (!entry.Exists() || !entry.IsFile())
continue;
if (n == 0) {
OpenFile(ref);
} else {
BMessage m(B_REFS_RECEIVED);
m.AddRef("refs", &ref);
gMainApp->NewWindow()->PostMessage(&m);
}
n++;
fPlaylist->AddRef(ref);
}
fPlaylist->Sort();
// open first file
if (fPlaylist->NextRef(&ref) == B_OK)
OpenFile(ref);
}

View File

@ -28,8 +28,10 @@
#include "Controller.h"
#include "ControllerView.h"
#include "VideoView.h"
#include "Player.h"
#include "Playlist.h"
class MainWin : public BWindow
class MainWin : public BWindow, public Player
{
public:
MainWin();
@ -48,7 +50,6 @@ public:
status_t KeyDown(BMessage *msg);
void CreateMenu();
void OpenFile(const entry_ref &ref);
void SetupWindow();
void SetupTrackMenus();
void SetWindowSizeLimits();
@ -56,6 +57,9 @@ public:
void ResizeVideoView(int x, int y, int width, int height);
void ShowFileInfo();
// from Player
void OpenFile(const entry_ref &ref);
void VideoFormatChange(int width, int height, float width_scale, float height_scale);
@ -85,6 +89,7 @@ public:
bool fHasFile;
bool fHasVideo;
Playlist * fPlaylist;
Controller * fController;
volatile bool fIsFullscreen;
volatile bool fKeepAspectRatio;

View File

@ -0,0 +1,10 @@
#ifndef __PLAYER_H
#define __PLAYER_H
class Player
{
public:
virtual void OpenFile(const entry_ref &ref) = 0;
};
#endif

View File

@ -0,0 +1,97 @@
/*
* Playlist.cpp - 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.
*
*/
#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;
}

View File

@ -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