diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index 9ade6e95c0..968ad7cf02 100644 --- a/src/apps/mediaplayer/Controller.cpp +++ b/src/apps/mediaplayer/Controller.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2007 Fredrik Modéen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index d5c1f6a6d5..110b90f4c9 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2007 Fredrik Modéen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License diff --git a/src/apps/mediaplayer/playlist/Playlist.cpp b/src/apps/mediaplayer/playlist/Playlist.cpp index 2e59f6fe02..2fe74fe03c 100644 --- a/src/apps/mediaplayer/playlist/Playlist.cpp +++ b/src/apps/mediaplayer/playlist/Playlist.cpp @@ -3,6 +3,7 @@ * * Copyright (C) 2006 Marcus Overhagen * Copyright (C) 2007 Stephan Aßmus + * Copyright (C) 2007 Fredrik Modéen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,7 +24,10 @@ #include #include #include -#include +#include +#include +#include +#include #include #include @@ -276,8 +280,8 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex) Playlist* playlist = add ? &temporaryPlaylist : this; entry_ref ref; - for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++) - AppendToPlaylistRecursive(ref, playlist); + for (int i = 0; refsReceivedMessage->FindRef("refs", i, &ref) == B_OK; i++) + AppendToPlaylistRecursive(ref, playlist); playlist->Sort(); @@ -309,7 +313,13 @@ Playlist::AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist) while (dir.GetNextRef(&subRef) == B_OK) AppendToPlaylistRecursive(subRef, playlist); } else if (entry.IsFile()) { - playlist->AddRef(ref); + BString mimeString = _MIMEString(&ref); + if (_IsMediaFile(mimeString)) + playlist->AddRef(ref); + else if (_IsPlaylist(mimeString)) { + printf("Playlist::AppendToPlaylistRecursive() - " + "TODO: implement playlist file loading\n"); + } } } @@ -332,6 +342,47 @@ Playlist::playlist_cmp(const void *p1, const void *p2) } +/*static*/ bool +Playlist::_IsMediaFile(const BString& mimeString) +{ + BMimeType superType; + BMimeType fileType(mimeString.String()); + + if (fileType.GetSupertype(&superType) != B_OK) + return false; + + // TODO: some media files have other super types, I think + // for example ASF has "application" super type... so it would + // need special handling + return (superType == "audio" || superType == "video"); +} + + +/*static*/ bool +Playlist::_IsPlaylist(const BString& mimeString) +{ + return mimeString.Compare("text/x-playlist") == 0; +} + + +/*static*/ BString +Playlist::_MIMEString(const entry_ref* ref) +{ + BFile file(ref, B_READ_ONLY); + BNodeInfo nodeInfo(&file); + char mimeString[B_MIME_TYPE_LENGTH]; + if (nodeInfo.GetType(mimeString) != B_OK) { + BMimeType type; + if (BMimeType::GuessMimeType(ref, &type) != B_OK) + return BString(); + + strlcpy(mimeString, type.Type(), B_MIME_TYPE_LENGTH); + nodeInfo.SetType(type.Type()); + } + return BString(mimeString); +} + + void Playlist::_NotifyRefAdded(const entry_ref& ref, int32 index) const { diff --git a/src/apps/mediaplayer/playlist/Playlist.h b/src/apps/mediaplayer/playlist/Playlist.h index f187e9122b..bf575df8e3 100644 --- a/src/apps/mediaplayer/playlist/Playlist.h +++ b/src/apps/mediaplayer/playlist/Playlist.h @@ -75,7 +75,7 @@ public: bool AddListener(Listener* listener); void RemoveListener(Listener* listener); - // support functions + // support functions void AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex = -1); static void AppendToPlaylistRecursive(const entry_ref& ref, @@ -83,6 +83,9 @@ public: private: static int playlist_cmp(const void* p1, const void* p2); + static bool _IsMediaFile(const BString& mimeString); + static bool _IsPlaylist(const BString& mimeString); + static BString _MIMEString(const entry_ref* entry); void _NotifyRefAdded(const entry_ref& ref, int32 index) const;