mediaplayer: Implement AppendM3uToPlaylist
Change-Id: I60a5146cae85ab7abb92a28ad142e5510c0a940e Reviewed-on: https://review.haiku-os.org/c/1337 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
a9b8a220a4
commit
0f856497bd
@@ -460,6 +460,8 @@ Playlist::AppendItems(const BMessage* refsReceivedMessage, int32 appendIndex)
|
||||
} else {
|
||||
if (_IsQuery(type))
|
||||
AppendQueryToPlaylist(ref, &subPlaylist);
|
||||
else if (_IsM3u(ref))
|
||||
AppendM3uToPlaylist(ref, &subPlaylist);
|
||||
else {
|
||||
if (!_ExtraMediaExists(this, ref)) {
|
||||
AppendToPlaylistRecursive(ref, &subPlaylist);
|
||||
@@ -573,6 +575,34 @@ Playlist::AppendPlaylistToPlaylist(const entry_ref& ref, Playlist* playlist)
|
||||
}
|
||||
|
||||
|
||||
/*static*/ void
|
||||
Playlist::AppendM3uToPlaylist(const entry_ref& ref, Playlist* playlist)
|
||||
{
|
||||
BFile file(&ref, B_READ_ONLY);
|
||||
FileReadWrite lineReader(&file);
|
||||
|
||||
BString line;
|
||||
while (lineReader.Next(line)) {
|
||||
if (line.FindFirst("#") != 0) {
|
||||
BPath path(line.String());
|
||||
entry_ref refPath;
|
||||
status_t err;
|
||||
|
||||
if ((err = get_ref_for_path(path.Path(), &refPath)) == B_OK) {
|
||||
PlaylistItem* item
|
||||
= new (std::nothrow) FilePlaylistItem(refPath);
|
||||
if (item == NULL || !playlist->AddItem(item))
|
||||
delete item;
|
||||
} else {
|
||||
printf("Error - %s: [%" B_PRIx32 "]\n", strerror(err), err);
|
||||
}
|
||||
}
|
||||
|
||||
line.Truncate(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*static*/ void
|
||||
Playlist::AppendQueryToPlaylist(const entry_ref& ref, Playlist* playlist)
|
||||
{
|
||||
@@ -620,7 +650,7 @@ Playlist::ExtraMediaExists(Playlist* playlist, PlaylistItem* item)
|
||||
Playlist::_ExtraMediaExists(Playlist* playlist, const entry_ref& ref)
|
||||
{
|
||||
BString exceptExtension = _GetExceptExtension(BPath(&ref).Path());
|
||||
|
||||
|
||||
for (int32 i = 0; i < playlist->CountItems(); i++) {
|
||||
FilePlaylistItem* compare = dynamic_cast<FilePlaylistItem*>(playlist->ItemAt(i));
|
||||
if (compare == NULL)
|
||||
@@ -720,6 +750,15 @@ Playlist::_IsPlaylist(const BString& mimeString)
|
||||
}
|
||||
|
||||
|
||||
/*static*/ bool
|
||||
Playlist::_IsM3u(const entry_ref& ref)
|
||||
{
|
||||
BString path(BPath(&ref).Path());
|
||||
return path.FindLast(".m3u") == path.CountChars() - 4
|
||||
|| path.FindLast(".m3u8") == path.CountChars() - 5;
|
||||
}
|
||||
|
||||
|
||||
/*static*/ bool
|
||||
Playlist::_IsQuery(const BString& mimeString)
|
||||
{
|
||||
@@ -753,7 +792,7 @@ Playlist::_BindExtraMedia(PlaylistItem* item)
|
||||
FilePlaylistItem* fileItem = dynamic_cast<FilePlaylistItem*>(item);
|
||||
if (!fileItem)
|
||||
return;
|
||||
|
||||
|
||||
// If the media file is foo.mp3, _BindExtraMedia() searches foo.avi.
|
||||
BPath mediaFilePath(&fileItem->Ref());
|
||||
BString mediaFilePathString = mediaFilePath.Path();
|
||||
@@ -762,7 +801,7 @@ Playlist::_BindExtraMedia(PlaylistItem* item)
|
||||
BDirectory dir(dirPath.Path());
|
||||
if (dir.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
|
||||
BEntry entry;
|
||||
BString entryPathString;
|
||||
while (dir.GetNextEntry(&entry, true) == B_OK) {
|
||||
|
||||
@@ -101,6 +101,8 @@ public:
|
||||
Playlist* playlist);
|
||||
static void AppendPlaylistToPlaylist(const entry_ref& ref,
|
||||
Playlist* playlist);
|
||||
static void AppendM3uToPlaylist(const entry_ref& ref,
|
||||
Playlist* playlist);
|
||||
static void AppendQueryToPlaylist(const entry_ref& ref,
|
||||
Playlist* playlist);
|
||||
|
||||
@@ -123,6 +125,7 @@ private:
|
||||
static bool _IsTextPlaylist(const BString& mimeString);
|
||||
static bool _IsBinaryPlaylist(const BString& mimeString);
|
||||
static bool _IsPlaylist(const BString& mimeString);
|
||||
static bool _IsM3u(const entry_ref& ref);
|
||||
static bool _IsQuery(const BString& mimeString);
|
||||
static BString _MIMEString(const entry_ref* ref);
|
||||
static void _BindExtraMedia(PlaylistItem* item);
|
||||
|
||||
Reference in New Issue
Block a user