MediaPlayer: Add support code for url items

* It needs further work to avoid the AudioSupplier being
recreated every time. It makes the BMediaFile to redo the sniffing
process various times.
This commit is contained in:
Dario Casalinuovo
2016-03-27 21:34:19 +02:00
parent e00ede2b48
commit bcf30a5eb5
3 changed files with 40 additions and 7 deletions
@@ -59,8 +59,7 @@ ImportPLItemsCommand::ImportPLItemsCommand(Playlist* playlist,
// init new entries
int32 added = 0;
for (int32 i = 0; i < fNewCount; i++) {
FilePlaylistItem* fileItem = dynamic_cast<FilePlaylistItem*>(temp.ItemAtFast(i));
if (fileItem && !Playlist::ExtraMediaExists(playlist, fileItem->Ref())) {
if (!Playlist::ExtraMediaExists(playlist, temp.ItemAtFast(i))) {
fNewItems[added] = temp.ItemAtFast(i)->Clone();
if (fNewItems[added] == NULL) {
// indicate bad object init
+34 -4
View File
@@ -464,7 +464,7 @@ Playlist::AppendRefs(const BMessage* refsReceivedMessage, int32 appendIndex)
if (_IsQuery(type))
AppendQueryToPlaylist(ref, &subPlaylist);
else {
if (!ExtraMediaExists(this, ref)) {
if (!_ExtraMediaExists(this, ref)) {
AppendToPlaylistRecursive(ref, &subPlaylist);
}
}
@@ -520,7 +520,7 @@ Playlist::AppendToPlaylistRecursive(const entry_ref& ref, Playlist* playlist)
BString mimeString = _MIMEString(&ref);
if (_IsMediaFile(mimeString)) {
PlaylistItem* item = new (std::nothrow) FilePlaylistItem(ref);
if (!ExtraMediaExists(playlist, ref)) {
if (!_ExtraMediaExists(playlist, ref)) {
_BindExtraMedia(item);
if (item != NULL && !playlist->AddItem(item))
delete item;
@@ -601,7 +601,26 @@ Playlist::NotifyImportFailed()
/*static*/ bool
Playlist::ExtraMediaExists(Playlist* playlist, const entry_ref& ref)
Playlist::ExtraMediaExists(Playlist* playlist, PlaylistItem* item)
{
FilePlaylistItem* fileItem = dynamic_cast<FilePlaylistItem*>(item);
if (fileItem != NULL)
return _ExtraMediaExists(playlist, fileItem->Ref());
// If we are here let's see if it is an url
UrlPlaylistItem* urlItem = dynamic_cast<UrlPlaylistItem*>(item);
if (urlItem == NULL)
return true;
return _ExtraMediaExists(playlist, urlItem->Url());
}
// #pragma mark - private
/*static*/ bool
Playlist::_ExtraMediaExists(Playlist* playlist, const entry_ref& ref)
{
BString exceptExtension = _GetExceptExtension(BPath(&ref).Path());
@@ -617,7 +636,18 @@ Playlist::ExtraMediaExists(Playlist* playlist, const entry_ref& ref)
}
// #pragma mark - private
/*static*/ bool
Playlist::_ExtraMediaExists(Playlist* playlist, BUrl* url)
{
for (int32 i = 0; i < playlist->CountItems(); i++) {
UrlPlaylistItem* compare = dynamic_cast<UrlPlaylistItem*>(playlist->ItemAt(i));
if (compare == NULL)
continue;
if (compare->Url() != url)
return true;
}
return false;
}
/*static*/ bool
+5 -1
View File
@@ -24,9 +24,11 @@
#include <List.h>
#include <Locker.h>
#include <Url.h>
#include "FilePlaylistItem.h"
#include "PlaylistItem.h"
#include "UrlPlaylistItem.h"
class BDataIO;
class BMessage;
@@ -115,13 +117,15 @@ public:
void NotifyImportFailed();
static bool ExtraMediaExists(Playlist* playlist, const entry_ref& ref);
static bool ExtraMediaExists(Playlist* playlist, PlaylistItem* item);
private:
Playlist(const Playlist& other);
Playlist& operator=(const Playlist& other);
// unimplemented
static bool _ExtraMediaExists(Playlist* playlist, const entry_ref& ref);
static bool _ExtraMediaExists(Playlist* playlist, BUrl* url);
static bool _IsImageFile(const BString& mimeString);
static bool _IsMediaFile(const BString& mimeString);
static bool _IsTextPlaylist(const BString& mimeString);