Fix type-based window-targeting
This commit is contained in:
parent
fca0d597ec
commit
b266e9ca53
|
@ -152,19 +152,24 @@ MediaPlayer::Window()
|
|||
|
||||
fWindowTargetHops = kTargetHops;
|
||||
|
||||
Song current;
|
||||
CurrentItem(¤t, 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(¤t, 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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -75,6 +75,15 @@ Song::Path()
|
|||
}
|
||||
|
||||
|
||||
BString
|
||||
Song::Type()
|
||||
{
|
||||
if (fType.IsEmpty())
|
||||
BNode(fPath.Path()).ReadAttrString("BEOS:TYPE", &fType);
|
||||
return fType;
|
||||
}
|
||||
|
||||
|
||||
int64
|
||||
Song::Duration()
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Ŝarĝante…
Reference in New Issue