-1

I am using AVQueuePlayer for playing multiple audio which are saved locally.

For reference please check below code,

for (int j = 0; j < arrPlayData.count; j++) {
                  
    path =[[NSBundle mainBundle] pathForResource:[[arrPlayData objectAtIndex:j] valueForKey:AUDIO_NAME] ofType:@"wav"];
    item = [[AVPlayerItem alloc] initWithURL:[NSURL fileURLWithPath:path]];
    if (_queuePlayer == nil) {
        _queuePlayer = [[AVQueuePlayer alloc] initWithPlayerItem:item];
     } else{
        [_queuePlayer insertItem:item afterItem:nil];
     }
}
[_queuePlayer setVolume:1.0];
[_queuePlayer play];

This is working fine,

Now I want to apply tempo for generated audio between 0 to 240 as shown in below image.

enter image description here

I am aware about the setRate: property and applied it as below,

[_queuePlayer setRate:sldValue/240.0];

Here, sldValue is selected value from above slider. Here if I select 240 from slider then rate becomes 1(Which plays audio in normal form - Original one). And as I select down value from slider then it will slow down the audio speed.

My query is how to increase audio speed then normal play. Or how this tempo exactly working?

Any help is really appreciated. Thanks in advance!

Community
  • 1
  • 1
iGatiTech
  • 2,306
  • 1
  • 21
  • 45
  • Basically a duplicate of http://stackoverflow.com/questions/6630356/avplayer-rate-property-does-not-work except for the part about apparently not knowing any elementary arithmetic – matt Mar 11 '16 at 05:22

1 Answers1

1
[_queuePlayer setRate:sldValue/245.0];

Here, sldValue is selected value from above slider. Here if I select 240 from slider then rate becomes 1(Which plays audio in normal form - Original one). And as I select down value from slider then it will slow down the audio speed.

That's because that's exactly what you're asking for. Think about it. If the slider is at 240, then sldValue/245.0 is approximately 1, which means normal, just as you say. And if you slide down, let's say to 120, then sldValue/245.0 is approximately 1/2, which is half speed.

The program is doing exactly what you are telling it to do. If that isn't what you want, then don't say that!

Also, you will need to set the audioTimePitchAlgorithm of your player items appropriately, or you won't be able to achieve a full range of rates. See: AVPlayer rate property does not work?

Community
  • 1
  • 1
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • What are the limits on the rate that you want? What speed should "0" represent, and what speed should "240" represent? Do you even _know_ what you want? – matt Mar 11 '16 at 05:10
  • Yes I very well know what I want. But no knowledge of tempo. That's why asking here. Also I know that "The program is doing exactly what I am telling it to do". But as it is playing in normal speed(Original audio) or less than the normal speed. So is it possible to increase audio speed. As I have tried it by setting rate to 2(static value). But I didn't find any speed change. – iGatiTech Mar 11 '16 at 05:16
  • Answer my question, please! What speed should "0" represent, and what speed should "240" represent? – matt Mar 11 '16 at 05:17
  • What I want is if my slider value is 120, it means 1/2. Then original audio should play, and if it goes beyond 1/2 then audio speed should increased. And if it goes below 1/2 then audio speed should decreased. – iGatiTech Mar 11 '16 at 05:23
  • That's what it means _now_. As I said in my answer, 120 means 1/2. So what's the problem? – matt Mar 11 '16 at 05:28
  • Thanks a lot for your questions.. Got my solution. Don't know why I have not noticed any speed increase in audio by setting rate to 2. By seeing your provided link http://stackoverflow.com/questions/6630356/avplayer-rate-property-does-not-work. I again checked it by setting rate to 2. And it's working. Thanks for your help! – iGatiTech Mar 11 '16 at 05:33
  • I was really confused for why rate: 2 is not working. But I just checked it audio speed by keeping digital clock with me. That in how much time audio is getting completed with rate:1 and rate:2. and yes there is difference between both rate value. So got my solution. I need to set slider value between 0 to 2 rate value. and not 0 to 1. – iGatiTech Mar 11 '16 at 05:37