MediaPlayer: Add Retrieving Track Number through Scripting

Also fix some backend logic

Change-Id: I4b24786ece4be1e9007686d46f6541d39df7a33b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/319
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
CodeforEvolution
2020-03-14 18:29:12 +00:00
committed by waddlesplash
parent 768f6b3bc4
commit 86950f4e76
2 changed files with 39 additions and 6 deletions
+25 -5
View File
@@ -148,6 +148,11 @@ static property_info sPropertyInfo[] = {
"Gets the URI of the currently playing item.", 0, "Gets the URI of the currently playing item.", 0,
{ B_STRING_TYPE } { B_STRING_TYPE }
}, },
{ "TrackNumber", { B_GET_PROPERTY, 0 },
{ B_DIRECT_SPECIFIER, 0 },
"Gets the number of the current track playing.", 0,
{ B_INT32_TYPE }
},
{ "ToggleFullscreen", { B_EXECUTE_PROPERTY }, { "ToggleFullscreen", { B_EXECUTE_PROPERTY },
{ B_DIRECT_SPECIFIER, 0 }, { B_DIRECT_SPECIFIER, 0 },
"Toggle fullscreen.", 0 "Toggle fullscreen.", 0
@@ -564,10 +569,25 @@ MainWin::MessageReceived(BMessage* msg)
} }
case 9: case 9:
{
if (msg->what == B_GET_PROPERTY) {
BAutolock _(fPlaylist);
const PlaylistItem* item = fController->Item();
if (item == NULL) {
result = B_NO_INIT;
break;
}
result = reply.AddInt32("result", item->TrackNumber());
}
break;
}
case 10:
PostMessage(M_TOGGLE_FULLSCREEN); PostMessage(M_TOGGLE_FULLSCREEN);
break; break;
case 10: case 11:
if (msg->what != B_GET_PROPERTY) if (msg->what != B_GET_PROPERTY)
break; break;
@@ -575,7 +595,7 @@ MainWin::MessageReceived(BMessage* msg)
fController->TimeDuration()); fController->TimeDuration());
break; break;
case 11: case 12:
{ {
if (msg->what == B_GET_PROPERTY) { if (msg->what == B_GET_PROPERTY) {
result = reply.AddInt64("result", result = reply.AddInt64("result",
@@ -590,7 +610,7 @@ MainWin::MessageReceived(BMessage* msg)
break; break;
} }
case 12: case 13:
{ {
if (msg->what != B_SET_PROPERTY) if (msg->what != B_SET_PROPERTY)
break; break;
@@ -604,11 +624,11 @@ MainWin::MessageReceived(BMessage* msg)
break; break;
} }
case 13: case 14:
result = reply.AddInt16("result", fPlaylist->CountItems()); result = reply.AddInt16("result", fPlaylist->CountItems());
break; break;
case 14: case 15:
{ {
int32 i = specifier.GetInt32("index", 0); int32 i = specifier.GetInt32("index", 0);
if (i >= fPlaylist->CountItems()) { if (i >= fPlaylist->CountItems()) {
@@ -183,7 +183,20 @@ status_t
FilePlaylistItem::GetAttribute(const Attribute& attribute, FilePlaylistItem::GetAttribute(const Attribute& attribute,
int32& value) const int32& value) const
{ {
switch (attribute) {
case ATTR_INT32_TRACK:
return _GetAttribute("Audio:Track", B_INT32_TYPE, &value,
sizeof(int32));
case ATTR_INT32_YEAR:
return _GetAttribute("Media:Year", B_INT32_TYPE, &value,
sizeof(int32));
case ATTR_INT32_RATING:
return _GetAttribute("Media:Rating", B_INT32_TYPE, &value,
sizeof(int32));
default:
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
}
} }