开发者

Access an mp3 in Cocos2D

I am play开发者_开发技巧ing a song in Cocos2D iphone using this line.

[[SimpleAudioEngine sharedEngine] playEffect:@"song.mp3"];

Suppose the mp3 is 1 min long, I want to play the song from 10 sec to 20 sec. Is it possible in Cocos2D iphone. Please help.


I don't think it is possible to "play the song from 10 sec to 20 sec" using the audio engine of cocos2d-iphone (which is named CocosDeshion).

SimpleAudioEngine is the main interface to CocosDeshion. Basically in cocos2d development we use audio files in two way - sound effect (short) and background music (long and usually loop). playEffect: is for the short ones, while playBackgroundMusic: and playBackgroundMusic:loop: is for the long ones. preloadBackgroundMusic: provides you the ability to cache the music in memory to avoid lag while playing, since they are often in compressed format.

As you can see in the documentation of SimpleAudioEngine (link above), there isn't such method for you to play a part of an audio file. Even the underlying class CDAudioManager doesn't support this.

I suggest to extract the 0:10 - 0:20 part as a separate audio file. But if you have a special reason to do this, you may want to use audio playback interfaces (such as AVAudioPlayer) in iOS SDK directly. Please refer to: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜