I've been making a project in cocos-2dx, but needed to create a .mm to select music from the iOS library to play in the background. I got it working by playing the music in the .mm file, but for various reasons, it needs to play in cocos-2dx using SimpleAudioEngine. I've tried converting the url's absoluteString to an NSString to an id to a const char* to move it back to the cocos-2dx files, but it still didn't run.
This is what it gave me for the absoluteString(ipod-library://item/item.m4a?id=456458322781804615)
.cc-
-(void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)collection{
if(collection){
MPMusicPlayerController* appMusicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[appMusicPlayer setQueueWithItemCollection:collection];
[appMusicPlayer play];
MPMusicPlayerController *iPodMusicPlayerController = [MPMusicPlayerController iPodMusicPlayer];
MPMediaItem *nowPlayingItem = [iPodMusicPlayerController nowPlayingItem];
NSURL *url = [nowPlayingItem valueForProperty:MPMediaItemPropertyAssetURL];
NSString *filePath= [url absoluteString];
NSString *filePath2 = [url path];
_songUrl = filePath;
}
-(id)returnsongUrl{
return _songUrl;
}
Second .mm
const char* MediaPicker::songUrl(){
id na1 = [[MediaPickerWrapper sharedIntance] returnsongUrl];
const char *cString = [na1 cStringUsingEncoding:NSASCIIStringEncoding];
return cString;
}
Cocos-2dx file
CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(media->songUrl());
CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(media->songUrl(),false);