Re: MusicPlayerIsPlaying() : is it done yet?
Re: MusicPlayerIsPlaying() : is it done yet?
- Subject: Re: MusicPlayerIsPlaying() : is it done yet?
- From: Zico Kolter <email@hidden>
- Date: Thu, 24 Jul 2003 15:29:11 -0400
As far as I know, there's no way of making the player automatically stop when
it has reached the end of a MIDI file. Here's how I do it:
First, determine when the end of the MIDI file occurs. You'll need to use a
MusicEventIterator for this. I don't have my mac with me here (and
unfortunately, the only updated documentation for the API is in the header
file), but I think the code is something like this:
MusicTrack track;
MusicEventIterator iterator;
MusicTimeStamp endTime;
NewMusicEventIterator(track, &iterator);
MusicEventIteratorSeek(iterator, kMusicTimeStamp_EndOfTrack);
MusicEventIteratorPreviousEvent(iterator);
MusicEventIteratorGetEventInfo(iterator ,&endTime, &eventType, &data, &size);
I think you might be able to get away with passing NULL for all the parameters
except timeStamp, but I've never actually done it. Anyway, at this point
timeStamp will be the time of the last event in the MIDI file. I'm not sure
how this works with some note events, because unlike with raw midi data, the
MusicPlayer APIs (and maybe the MIDI file spec itself?) use note events with
duration rather than simply using subsequent note on/off events. So if the
last event is a note event of this type, then you might have to use
MusicEventIteratorGetEventInfo() to get the note information for the note
event, and then add the note's duration to whatever value you got for the
time stamp. I'm not sure that this is how it works, though (it might simply
send both the note on and note off event to the MIDIEndpoint, in which case
the method above would work fine), so you'll have to try it out and see.
Now after you get this you have to spawn some sort of timer when you call
MusicPlayerStart(). NSTimer or it's Core Foundation equivalent will work
well for this. Then do something like this in the timer:
MusicTimeStamp currentTime;
MusicPlayerGetTime(player, ¤tTime);
if (currentTime > endTime && currentTime < kMusicTimeStamp_EndOfTrack) {
MusicPlayerStop(player);
// kill the timer
}
It's important to check to make sure that currentTime <
kMusicTimeStamp_EndOfTrack. I haven't gotten around to reporting this,
assuming it's a bug and not just an error with my coding, but I've found that
occasionally, usually just after playing has started, MusicPlayerGetTime()
will return bogus values.
So I guess it's a bit more complicated than it might have first appeared, but
still several orders of magnitude easier than writing your own midi file
parser. Again, I haven't actually checked those code segments, but they give
you the general idea of how to do it, though you'd probably want to add error
checking to make sure nothing weird was happening.
As for the thing you mentioned before, about setting the MIDIEndpoints, I
don't know, as I've only used this with a MusicDevice. But I'd presume that
setting the MIDIEndpoint would not "claim" the endpoint, and you'd still have
to dispose of it yourself. I would not think that you would need to do the
GetOld()/SetNew()/DoStuff()/SetOld() dance, either.
Hope that helps,
Zico
On Thursday 24 July 2003 1:37 pm, Roy Lovejoy wrote:
>
I spoke too soon.. Apparently, MusicPlayerIsPlaying seems to want to
>
keep the party going by
>
_NEVER_ returning false..
>
>
Boolean stillPlaying = false;
>
err = MusicPlayerIsPlaying(player, &stillPlaying);
>
>
stillPlaying is true, even long after the end of the midi sequence is
>
over.
>
>
is there anyway of determining when the sequence is over, after issuing
>
a MusicPlayerStart() ?
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.