开发者

How do you display song lyrics in Karaoke style on the iPhone?

I am currently creating an app that plays music. I would like to add a feature that shows the music lyrics while the music plays, with the current position of the text marked to match the current position in the song. The Bouncing Ball effect, just like you see on every Karaoke screen as the song plays. I have been looking into extending my caf files, adding "string chunks" and then reading them out again. Is this the correct way to do this? Does anybody know of a better/easier/normal way t开发者_Python百科o achieve my goal? As I am not sure how I would synchronize everything, I would be happy for any suggestions, code examples or helpful comments. Maybe somebody has done this before and would be happy to advise me.

Thanks in advance for any information offered.

Alan


Most Karaoke apps these days use the .Kar file extension. It's a slightly butchered MIDI file with some annotations and it's pretty small in file size.

I have no idea where you'd start to read it though. You could ask these guys: http://www.ikaraokeapp.com/

Most little devs are happy to help others out.


The standard way to do this is using the kar file extension as suggested by the other answer. Here are some more details.

The .kar extension just signifies that a standard midi file contains lyric information. To build your karaoke player you need to do two things: play the instrument part of the midi file and display the lyrics.

This can be achieved in two ways. Either you could use the built in MusicPlayer to play the midi file and then access the lyric information from a virtual endpoint: here

You would need to access midi meta messages with codes 0x01 (text) or 0x05 (lyric). These messages store the lyric data as a series of hex numbers where each hex number represents an ascii character.

This approach allows you to play the MIDI file and access the lyrics. The problem is that you need to be able to display the lyrics ahead of time so the user can read them before they're played.

To do this you could parse the midi file manually: here

You would need to loop over the MIDI file and extract the text lyrics with their time stamps. Then you could display a section of lyrics ahead of time and change the colour or do a bouncing ball effect as the lyrics became due.


You should be able to do this through the MusicPlayer API, specifically the MusicTrack MIDIMetaEvent assuming midi type music is acceptable.

MIDIMetaEvent

Describes a MIDI metaevent such as lyric text, time signature, and so on.

typedef struct MIDIMetaEvent {
   UInt8    metaEventType;
   UInt8    unused1;
   UInt8    unused2;
   UInt8    unused3;
   UInt32   dataLength;
   UInt8    data[1];
} MIDIMetaEvent;

Alternately, you might also made some headway looking at iD3 metadata for storing lyrics and timing info.

Either way, there will be lots of file prep in getting the lyrics and timing into the music files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜