Can URL's be used with SimpleAudioEngine

I’m extracting the URLs for songs from songs in the IOS library (such as ipod-library://item/item.m4a?id=456458322781804615).
Is it possible to use this to play audio using the simpleAudioEngine?

I believe it uses AVAudioPlayer at its core, and if true, then you should be able to do that.
Have you tried it? You should try it and report back your results.

I’ve been unable to find a way to transfer the url from the objective C file to C++, but I was able to transfer over the absolute string of the url. This however resulted in no song being played.

Obj C

    NSURL *url = [nowPlayingItem valueForProperty:MPMediaItemPropertyAssetURL];
    NSString *filePath= [url absoluteString];
    NSString *filePath2 = [url path];
    _songUrl = filePath;

C++

    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(media->songUrl());
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(media->songUrl(),false);

here is songUrl results ipod-library://item/item.m4a?id=653287291573311281

I’ll try to look at it this week.

If you’re already writing ObjC code, and because this is a single platform issue and feature, why not just load up and play a AVAudioPlayer yourself instead? Or use the lower-level AVQueuePlayer? You could just send out a method or notification to the ObjC code to play? Or store all player and iTunes music item states outside the c++ part of your game?

Just a thought.

1 Like

I’m also trying to play URLs from the web using SimpleAudioEngine. It seems like loading a resource from the web is a fairly basic feature that should be supported.

@stevetranby, this looks like what I’ll end up having to do with some callStaticMethod magic, but it definitely seems like a hack. Thanks.

How about downloading mp3 first using HttpClient & HttpRequest and then play?

1 Like

I wasn’t sure that the URLs used by SimpleAudioEngine could be arbitrary paths (e.g. application directories or application data directories), per https://gist.github.com/granoeste/5574148 – I was only under the impression that they were just references to packaged Cocos game assets. Regardless, I agree, it’s worth a shot.