1

I studied a lot but did not find any good answer. My problem is i am calculating beats per minute of song. I used Bass api for that, now problem is I am able to get bpm of a file which I have in my resource folder but I have to get bpm of all songs of iPod library. I am getting path of song from MPMediaItemPropertyAssetURL property of MpMediaItem but when passing this one in api, it says stream can't load BASS_StreamCreateFile(). From my point of view, I am not getting right path of song. How can we access valid path? Did any one access iPod library song with external api? Please help me .

Thanks.

CODE IS THIS:

NSURL *assetURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
NSString *respath = [NSString stringWithFormat:@"%@",[assetURL absoluteString]];

BASS_SetConfig(BASS_CONFIG_IOS_MIXAUDIO, 0); // Disable mixing. To be called before BASS_Init.

if (HIWORD(BASS_GetVersion()) != BASSVERSION) {
    NSLog(@"An incorrect version of BASS was loaded");
}

// Initialize default device.
if (!BASS_Init(-1, 44100, 0, NULL, NULL)) {
    //textView.text = [NSString stringWithFormat:@"%@  CAN'T Load Stream",textView.text];   

}


DWORD chan1;
if(!(chan1=BASS_StreamCreateFile(FALSE, [respath UTF8String], 0, 0, BASS_SAMPLE_LOOP))) {
    NSLog(@"Can't load stream!");
    textView.text = [NSString stringWithFormat:@"%@  not loading...",textView.text];    

}

mainStream=BASS_StreamCreateFile(FALSE, [respath cStringUsingEncoding:NSUTF8StringEncoding], 0, 0, BASS_SAMPLE_FLOAT|BASS_STREAM_PRESCAN|BASS_STREAM_DECODE);

float playBackDuration=BASS_ChannelBytes2Seconds(mainStream, BASS_ChannelGetLength(mainStream, BASS_POS_BYTE));
NSLog(@"Play back duration is %f",playBackDuration);
HSTREAM bpmStream=BASS_StreamCreateFile(FALSE, [respath UTF8String], 0, 0, BASS_STREAM_PRESCAN|BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE);
//BASS_ChannelPlay(bpmStream,FALSE);
BpmValue= BASS_FX_BPM_DecodeGet(bpmStream,0.0,
                                playBackDuration,
                                MAKELONG(45,256),
                                BASS_FX_BPM_MULT2| BASS_FX_BPM_MULT2 | BASS_FX_FREESOURCE,
                                (BPMPROCESSPROC*)proc);

textView.text = [NSString stringWithFormat:@"%@  %f",textView.text,BpmValue];   
tipycalFlow
  • 7,594
  • 4
  • 34
  • 45
  • Please check code and tell whats going wrong? – Narendra Kumar Mar 30 '12 at 05:54
  • Hello Devang did u see code and have any solution? – Narendra Kumar Apr 02 '12 at 04:46
  • Are you storing songs in Document directory ?? And are you converting it in any other format ? – Devang Apr 02 '12 at 04:55
  • Ya i dont have any other option. Dude you also used this api for calculating bpm of songs. what you did? Now ,first i am exporting song from ipod library and putting it in document directory and then passing path of file to BASS api. – Narendra Kumar Apr 02 '12 at 05:36
  • What does your `respath` look like? Use `NSLog` and post that too! – tipycalFlow Apr 02 '12 at 05:40
  • @NarendraKumar : Enable `iTunes sharing` and check whether your songs are being copied successfully in document directory or not ? And I am converting songs in `.mp3`. what about you ? – Devang Apr 02 '12 at 06:06
  • @tipycalFlow dude when i am printing MPMediaItemPropertyAssetURL of item then it's printing like:ipodlibrary://item/item/songname.mp3?id=18313100304104 this. my question is straight can we use ipod library file as we use our local file in Resource folder.If yes then how can we generate resource path of it? – Narendra Kumar Apr 02 '12 at 09:42
  • @Devang when i am using conecpt to copy files in Document directory of app and then get path of it, which working fine. I want use filepath of file directly without exporting it in Document directory. Is it possible? – Narendra Kumar Apr 02 '12 at 09:45
  • @NarendraKumar : Have you verified that it is copying song successfully or not ? – Devang Apr 02 '12 at 09:50
  • @NarendraKumar See the [`MPMediaPickerController`](https://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMediaPickerController_ClassReference/Reference/Reference.html) reference. I don't think Apple allows us to use iPod songs in any other way! Even in that, we're only allowed to play/pause the songs, not use their paths! – tipycalFlow Apr 02 '12 at 10:08
  • @Devang i dont want to copy song file from ipod librarry into Document folder. I want to access directly all songs from ipod library and pass their path in BASS Api method BASS_StreamCreateFile() and get bpm.In case of copying i am able to do all things which i want. – Narendra Kumar Apr 02 '12 at 11:12
  • @NarendraKumar : From my point of view it is better to copy image at Document Directory. – Devang Apr 02 '12 at 11:23
  • @Devang dude but it will take lots of time.Suppose if you have 1000 song then to calculate bpm of all songs will be very irritating task.Client not like that. – Narendra Kumar Apr 02 '12 at 16:48
  • @NarendraKumar : then, Have you tried to get BPM using `MPMediaItemPropertyBeatsPerMinute` property? I dont know how you are using song directly from the iPhone library. I use to copy particular song in document directory as per my requirement. Post your code How you are using song without copying it to your app.! – Devang Apr 03 '12 at 04:19
  • @Devang I did lots of R&D at last i used same approach as you.First copy song and put in document directory and calculate bpm and delete it. – Narendra Kumar Apr 09 '12 at 12:35
  • @NarendraKumar : And what happened ? – Devang Apr 09 '12 at 12:39
  • I able to calculate bpm of all song and save bpms locally and categorized all songs of ipod library on the basis of bpms range. – Narendra Kumar Apr 09 '12 at 15:17

0 Answers0