Fix type-based window-targeting

This commit is contained in:
Jaidyn Ann 2022-08-09 14:35:44 -05:00
parent fca0d597ec
commit b266e9ca53
4 changed files with 34 additions and 8 deletions

View File

@ -152,19 +152,24 @@ MediaPlayer::Window()
fWindowTargetHops = kTargetHops;
Song current;
CurrentItem(&current, false);
for (int32 i = CountWindows() - 1; i >= 0; i--) {
MediaPlayer mp(i, MP_BY_INDEX);
if (mp.IsValid()) {
if (fWindowTarget == MP_BY_LATEST)
return i;
return fWindowIndex = i;
Song current;
BString type;
if (CurrentItem(&current, false)
&& BNode(current.Path().Path()).ReadAttrString("BEOS:TYPE", &type) == B_OK)
if ((type.StartsWith("audio") && fWindowTarget == MP_BY_TYPE_AUDIO)
|| (type.StartsWith("video") && fWindowTarget == MP_BY_TYPE_VIDEO))
return i;
Song mpcurrent;
mp.CurrentItem(&mpcurrent, false);
// If the current item's type is correct, we'll keep it
if (!current.InitCheck() || !_MatchesTypeTarget(current.Type(), fWindowTarget))
if (mpcurrent.InitCheck() && _MatchesTypeTarget(mpcurrent.Type(), fWindowTarget))
return fWindowIndex = i;
else
fWindowIndex = -1;
}
}
return fWindowIndex;
@ -259,6 +264,14 @@ MediaPlayer::_ScriptingCall(const char* attribute, BMessage* send, BMessage* rep
}
bool
MediaPlayer::_MatchesTypeTarget(BString mimetype, target typeTarget)
{
return (mimetype.StartsWith("video") && typeTarget == MP_BY_TYPE_VIDEO)
|| (mimetype.StartsWith("audio") && typeTarget == MP_BY_TYPE_AUDIO);
}
const char*
MediaPlayer::_UriToPath(BString URI)
{

View File

@ -71,6 +71,7 @@ private:
void _ScriptingCall(const char* attribute, BMessage* send, BMessage* reply,
int32 trackIndex = MP_NO_TRACK, bool window = true);
bool _MatchesTypeTarget(BString mimetype, target typeTarget);
const char* _UriToPath(BString URI);
int32 fWindowIndex;

View File

@ -75,6 +75,15 @@ Song::Path()
}
BString
Song::Type()
{
if (fType.IsEmpty())
BNode(fPath.Path()).ReadAttrString("BEOS:TYPE", &fType);
return fType;
}
int64
Song::Duration()
{

View File

@ -18,6 +18,7 @@
#define SONG_H
#include <Path.h>
#include <String.h>
class BBitmap;
@ -32,6 +33,7 @@ public:
BBitmap* Cover();
BPath Path();
BString Type();
int64 Duration();
int operator ==(Song a)
@ -60,6 +62,7 @@ private:
int64 fDuration;
BPath fPath;
BString fType;
};
#endif // SONG_H