Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:35:45+00:00 2026-05-31T10:35:45+00:00

So, I’m trying to figure out the MusicPlayer API for iOS. I have been

  • 0

So, I’m trying to figure out the MusicPlayer API for iOS. I have been able to get a MIDI to play, so my sequence is there and populated with something useful but I can’t seem to get access to the tracks (or in this case track, as there is only one music track, the other is a tempo track).

If I run a MusicSequenceGetTrackCount on “mySequence” I get a return of 2; this is expected.

If I run a MusicSequenceGetInfoDictionary, it returns 3 entries:

Printing description of sequenceInfo:
{
    tempo = 120;
    "time signature" = "4/4";
    title = "RHand";
}

This makes sense since all of this info matches up with my track.

So, all of this would make me think if I use the method MusicSequenceGetIndTrack(MusicSequence inSequence, UInt32 inTrackIndex, MusicTrack *outTrack) I should be able to output the track so I can make some modification.

Here’s my code so far. If anyone could take a look and see where I’m going wrong, that’d be great. Also, if anyone has some good resources about using MusicPlayer, I’d be really grateful. Thanks.

ViewController.h

#import <UIKit/UIKit.h>
#import <AudioToolbox/MusicPlayer.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UILabel *noteDisplayLabel;
@property MusicSequence mySequence;
@property MusicPlayer player;
@property MusicEventIterator iterator;
@property MusicTrack RHand;
@property MusicTrack LHand;


- (IBAction)practiceLesson:(id)sender;
- (IBAction)changeTempo:(id)sender;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize noteDisplayLabel, mySequence, player, iterator, RHand, LHand;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    CFBundleRef appBundle = CFBundleGetMainBundle();
    CFStringRef filename = CFSTR("simpleCScale");
    CFStringRef ext = CFSTR("mid");

    CFURLRef fileLocation = CFBundleCopyResourceURL(appBundle, filename, ext, NULL);

    NewMusicSequence(&mySequence);

    MusicSequenceFileLoad(mySequence, fileLocation, 0, kMusicSequenceLoadSMF_ChannelsToTracks);

    NewMusicPlayer(&player);

    UInt32 trackCount;
    MusicSequenceGetTrackCount(mySequence, &trackCount);

    NSLog(@"Number of tracks: %lu", trackCount);

    CFDictionaryRef sequenceInfo;
    sequenceInfo = MusicSequenceGetInfoDictionary(mySequence);

    UInt32 trackIndex = 0;
    MusicTrack track;
    MusicSequenceGetIndTrack (mySequence,trackIndex,&track);

    MusicEventIterator iter;
    Boolean hasEvent = 0;
    NewMusicEventIterator(track, &iter);

    Boolean hasNextEvent = 1;

    while (hasNextEvent == 1) {
        MusicEventIteratorHasCurrentEvent(iter, &hasEvent);
        NSLog(@"Has Event: %i", hasEvent);

        MusicTimeStamp timestamp;
        MusicEventType eventType = 0;
        void *eventData = NULL;
        UInt32 eventDataSize;

        MusicEventIteratorGetEventInfo(iter, &timestamp, &eventType, eventData, &eventDataSize);
        NSLog(@"Event %f: Type = %lu, Data = %p, Size = %lu", timestamp, eventType, eventData, eventDataSize);

        MusicEventIteratorNextEvent(iter);
        MusicEventIteratorHasNextEvent(iter, &hasNextEvent);
        NSLog(@"More Events? : %i", hasNextEvent);
    }
}

- (void)viewDidUnload
{
    [self setNoteDisplayLabel:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (IBAction)practiceLesson:(id)sender {
    MusicPlayerSetSequence(player, mySequence);
    MusicPlayerStart(player);
}

- (IBAction)changeTempo:(id)sender {
}
@end

EDIT

Tried doing the following in the viewDidLoad method but it didn’t work:

UInt32 trackIndex = 1;
MusicTrack *track;
MusicSequenceGetIndTrack (mySequence,trackIndex,&track);

EDIT

Updated the above code to include changes. I have the eventIterator working now but I can’t seem to get any event data out of it? Running the program gives me the following output:

2012-03-13 14:09:39.709 musicPlayerSandbox[61775:f803] Number of tracks: 2
2012-03-13 14:09:39.711 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.712 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.713 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.714 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.714 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.715 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.716 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.716 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.717 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.718 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.719 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 7, Data = 0x0, Size = 4
2012-03-13 14:09:39.719 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.720 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.845 musicPlayerSandbox[61775:f803] Event 0.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.846 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.846 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.847 musicPlayerSandbox[61775:f803] Event 1.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.847 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.848 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.849 musicPlayerSandbox[61775:f803] Event 2.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.850 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.850 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.851 musicPlayerSandbox[61775:f803] Event 3.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.851 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.852 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.853 musicPlayerSandbox[61775:f803] Event 4.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.887 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.888 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.888 musicPlayerSandbox[61775:f803] Event 5.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.889 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.890 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.891 musicPlayerSandbox[61775:f803] Event 6.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.891 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.892 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.893 musicPlayerSandbox[61775:f803] Event 7.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.893 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.894 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.895 musicPlayerSandbox[61775:f803] Event 8.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.899 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.900 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.901 musicPlayerSandbox[61775:f803] Event 9.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.902 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.902 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.903 musicPlayerSandbox[61775:f803] Event 10.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.904 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.905 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.905 musicPlayerSandbox[61775:f803] Event 11.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.906 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.907 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.908 musicPlayerSandbox[61775:f803] Event 12.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.908 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.909 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.928 musicPlayerSandbox[61775:f803] Event 13.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.929 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.930 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.930 musicPlayerSandbox[61775:f803] Event 14.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.931 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.932 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.932 musicPlayerSandbox[61775:f803] Event 15.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.933 musicPlayerSandbox[61775:f803] More Events? : 1
2012-03-13 14:09:39.933 musicPlayerSandbox[61775:f803] Has Event: 1
2012-03-13 14:09:39.934 musicPlayerSandbox[61775:f803] Event 16.000000: Type = 6, Data = 0x0, Size = 8
2012-03-13 14:09:39.935 musicPlayerSandbox[61775:f803] More Events? : 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:35:46+00:00Added an answer on May 31, 2026 at 10:35 am

    To access any track you will first need to access musicSequence. In your case you have mySequence
    for this also you know the total number of tracks in music sequence as trackCount. Now to access particular track you will simply need to use

    MusicTrack *track;
    MusicSequenceGetIndTrack (mySequence,trackIndex,&track);
    

    This will give you track. Also, make sure that trackIndex < trackCount.

    Update

    As per document.

    The music track and related opaque types are declared in the MusicPlayer.h header file.

    So you will need to use (MusicTrack is opaque type not a class.)

    MusicTrack track; //without star sign. rest remains the same.
    

    Update for EventIterator

    As you said MusicEventIteratorGetEventInfo() method takes parameter const void **outEventData for event data therefore you will need to pass it as &outEventData and not the outEventData only.

    So in your code change following line:

    MusicEventIteratorGetEventInfo(iter, &timestamp, &eventType, &eventData, &eventDataSize);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I know there's a lot of other questions out there that deal with this
I have been unable to fix a problem with Java Unicode and encoding. The
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.