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 8044851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:21:39+00:00 2026-06-05T05:21:39+00:00

I need to create a new NSNumber or integer property called primaryKey to be

  • 0

I need to create a new NSNumber or integer property called primaryKey to be included with all AVAudioPlayer objects that I create so that I can read the value of that property within the audioPlayerDidFinishPlaying callback and know exactly which database record was played.

The reason I need to do this is: I can’t use the player URL property to determine which database record it was since the same sound file can be used multiple times within the playlist.

How can I add a new property to an existing iOS class like this?


Example:

AVAudioPlayer *newAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];  

self.theAudio = newAudio; // automatically retain audio and dealloc old file if new file is loaded
if (theAudio != nil) [audioPlayers addObject:theAudio];

[newAudio release];

[theAudio setDelegate: theDelegate];
[theAudio setNumberOfLoops: 0];
[theAudio setVolume: callVolume];

// This is the new property that I want to add
[theAudio setPrimaryKey: thePrimaryKey];

[theAudio play];

Then I’d retrieve it in the callback like this:

- (void) audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag 
{    
   NSNumber *finishedSound = [NSNumber numberWithInt:[player primaryKey]];

   // Do something with this information now...
}
  • 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-06-05T05:21:41+00:00Added an answer on June 5, 2026 at 5:21 am

    You can create a subclass and add your property just like you would when subclassing anything.

    Interface

    @interface MyAudioPlayer : AVAudioPlayer
    
    @property (nonatomic) int primaryKey;
    
    @end
    

    Implementation

    @implementation MyAudioPlayer
    
    @synthesize primaryKey = _primaryKey;
    
    @end
    

    Creating

    MyAudioPlayer *player = [[MyAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
    player.primaryKey = thePrimaryKey;
    ...
    

    Delegate

    - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
        if ([player isKindOfClass:[MyAudioPlayer class]]) {
            MyAudioPlayer *myPlayer = (MyAudioPlayer *)player;
            NSNumber *primaryKeyObject = [NSNumber numberWithInt:myPlayer.primaryKey];
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation, where I need to create a new JavaScript object that
Can You tell me about subj? For example I need to create new custom
I need to create a single installer that I can distribute to machines running
I am not looking to create new events. I need to create a canvas
I'm very new at this, but I need to create new tables from existing
I have a Excel sheet with two columns and I need to create new
I need to create a new line of data within an array where the
I am new to Zkoss and i need to create completely new css theme
I have the following three arrays and need to create a new two-dimensional array
I need to create an entirely new Sql Server 2008 database and want to

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.