0

I have developed an iOS app with audio playback functionality. I have used a Progress View for the playback of the audio and have used a Horizontal Slider for the volume control.

2 Things I need help with:

  1. The Progress View is uneditable. By that, I mean when the track is playing the user should be able to drag it to certain point and play from there. Same as iOS music app or Spotify??

  2. The Volume slider allows user to adjust volume but it doesnt work alongside the iOS device audio. Meaning, when the audio level is changed, it should change on the actual device.

Here is my code:

NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"01" ofType:@"MP3"];
NSURL *url = [NSURL fileURLWithPath:stringPath];




NSError *error;

avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];

[avPlayer setNumberOfLoops:2];

[avPlayer setVolume:self.sliderVolumeOutlet.value];

[avPlayer stop];

[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateMyProgress) userInfo:nil repeats:YES];


-(void)updateMyProgress
{
    float progress = [avPlayer currentTime]/[avPlayer duration];
    self.myProgressView.progress = progress;
}

- (IBAction)sliderVolumeAction:(id)sender {
    UISlider *mySlider = sender;
    [avPlayer setVolume:mySlider.value];
}

- (IBAction)stopButton:(id)sender {
    [avPlayer stop];
    [avPlayer setCurrentTime:0];
}

- (IBAction)pauseButton:(id)sender {
    [avPlayer pause];
}


- (IBAction)playButton:(id)sender {

    [avPlayer play];

}

- (IBAction)backButtonEvent:(id)sender {
    [self dismissViewControllerAnimated:YES completion:NULL];
}


- (void)viewWillDisappear:(BOOL)animated
{
    [avPlayer stop];
}
Omar
  • 979
  • 3
  • 16
  • 26
  • http://stackoverflow.com/questions/6020844/how-to-add-the-mpvolumeview-via-xcode-designer this link will help you to add mpvolumeview and in other case you can use uislider – square Oct 02 '13 at 17:04

1 Answers1

0
  1. Use UISlider instead of a progress view.

  2. Use MPVolumeView for volume control. Just place it in your view hierarchy, it'll work without any aditional wiring.

Vadim Yelagin
  • 3,112
  • 2
  • 17
  • 20
  • 1. I tried that but then get the following error: Property 'progress' not found on object of type UISlider 2. Thank you, worked perfectly!! :) Please help on the first point – Omar Oct 02 '13 at 17:00
  • Progress view has `progress` property, slider has `value` property. Use `value` instead of `progress` when you use slider instead of progress view. – Vadim Yelagin Oct 03 '13 at 02:11