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

后端 未结 3 1758
深忆病人
深忆病人 2021-01-07 08:32

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 marke

相关标签:
3条回答
  • 2021-01-07 09:08

    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.

    0 讨论(0)
  • 2021-01-07 09:29

    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.

    0 讨论(0)
  • 2021-01-07 09:32

    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 讨论(0)
提交回复
热议问题