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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:09:29+00:00 2026-05-24T14:09:29+00:00

NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filename error:nil] From the file attribute keys, you can

  • 0
NSDictionary* fileAttributes = 
    [[NSFileManager defaultManager] attributesOfItemAtPath:filename 
                                                     error:nil]

From the file attribute keys, you can get the date, size, etc. But how do you get the duration?

  • 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-24T14:09:30+00:00Added an answer on May 24, 2026 at 2:09 pm

    In the ‘File Attribute Keys’ of the NSFileManager class reference you can see that there is no key to use that will return the duration of a song. All the information that the NSFileManager instance gets about a file is to do with the properties of the actual file itself within the operating system, such as its file-size. The NSFileManager doesn’t actually interpret the file.

    In order to get the duration of the file, you need to use a class that knows how to interpret the file. The AVFoundation framework provides the exact class you need, AVAsset. You can instantiate an instance of this abstract class using the concrete subclass AVURLAsset, and then provide it an NSURL which points to the audio file you wish to get the duration. You can then get the duration from the AVAsset instance by querying its duration property.

    For example:

    AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:audioFileURL options:nil];
    CMTime audioDuration = audioAsset.duration;
    float audioDurationSeconds = CMTimeGetSeconds(audioDuration);
    

    Note that AVFoundation is designed as a heavily asynchronous framework in order to improve performance and the overall user experience. Even performing simple tasks such as querying a media file’s duration can potentially take a long period of time and can cause your application to hang. You should use the AVAsynchronousKeyValueLoading protocol to asynchronously load the duration of the song, and then update your UI in a completion handler block. You should take a look at the ‘Block Programming Guide’ as well as the WWDC2010 video titled, ‘Discovering AV Foundation’, which is available free at https://developer.apple.com/videos/wwdc/2010.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NSDictionary *attributes = nil ; *attributes = [filemanager attributesOfItemAtPath:path error:nil] ; fails with ...
I have an NSDictionary with 5 keys and corresponding values. How can I set
I'm using a NSDictionary to get a NSString from a plist with the following
In Cocoa, you can get the attributes of a file as follow NSString *path
I get the following NSDictionary when I parse a JSON response from my server:
I have an NSDictionary instance created via NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
i have a NSDictionary and i get objects and keys in 'id' type format
Code: [self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@PropertySubtype2fTitle, @), kTitleKey, publishNoOfRoomsViewController, kViewControllerKey, nil]]; menuList is a NSMutableArray.
Why does this code...: NSDictionary *testDictionary = [NSDictionary dictionaryWithObjectsAndKeys:kABOtherLabel, @other, kABWorkLabel, @work, nil]; //
I have created 5 NSDictionary's. I stored them in NSArray. I need to get

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.