0

I am playing an audio file named 'myTrack.mp3' with SimpleAudioEngine as:

[[SimpleAudioEngine sharedEngine]playBackgroundMusic:@"myTrack.mp3" loop:NO];

The audio if of the length of 00:17 seconds, and my plays the whole file. But now I need to play only the portion between time 00:08 and 00:14. Is it is possible in Cocos2d?

Thanks.

Thampuran
  • 644
  • 5
  • 22

1 Answers1

1

I am not familiar with SimpleAudioEngine but with the standard AVQueuePlayer you can do:

1) seekToTime. e.g. ([_player seekToTime:CMTimeMakeWithSeconds(8.0, 1.0)])

2) then add time observer to the player:

 _timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1.0, 1.0)
                                                  queue:NULL
                                             usingBlock:^(CMTime time) {
                                                 check current duration and stop the playback. 
                                             }];
kabarga
  • 803
  • 6
  • 11
  • And if I remember correctly CocosDenshion uses AVAudioPlayer behind the scenes for (background) music playback. Don't think it's accessible through the simple interface, must be in CDAudioManager or similar. – CodeSmile Oct 01 '14 at 12:13
  • Sorry, but what is the 'timeObserver' object type? And while adding those lines, I am getting Mach-O linker error: 'Undefined symbols for architecture i386:'. Can u help me pls? – Thampuran Oct 01 '14 at 15:37
  • id timeObserver. finally you can do [_player removeTimeObserver:_timeObserver] and set it to nil. strange issue with i386. what symbols? – kabarga Oct 01 '14 at 18:13