I have App that play the Song from the iPod library and i also have to play the song in background so i take avplayer. but i dont set its volume. is their any way to set the volume.
Asked
Active
Viewed 6,225 times
4 Answers
1
Notification popup with volume slider inside - Hoper this helps:
- (IBAction)volume{
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame: CGRectMake(10, 37, 260, 20)] autorelease];
UIAlertView *volumeAlert = [[UIAlertView alloc] initWithTitle:@"Volume" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[volumeView sizeToFit];
[volumeAlert addSubview:volumeView];
/*
for (UIView *view in [volumeView subviews]) {
if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
volumeViewSlider = view;
}
}*/
[volumeAlert show];
[volumeAlert release];
}

Patrick R
- 1,949
- 3
- 32
- 58
1
You can't play an ipod-Library track using AVAudioPlayer
. AVAssetExportSession
has a BUG in IOS.5 so it's unable to export from iPod library in mainbundle, So if you want to play iPod tracks, your stuck with AVPlayer
. Sadly only Hardware buttons can control the volume of this.
0
Pls check this Adjusting the volume of a playing AVPlayer
If you can use AVAudioPlayer
you can easily use its property volume
0
To use a slider and use this code,
In .h file write this code and don't forget to implement AVAudio framework,
#import UIKit/UIKit.h>
#import Foundation/Foundation.h>
#import AVFoundation/AVFoundation.h>
@interface volumechangerViewController : UIViewController <AVAudioPlayerDelegate>
{
IBOutlet UIButton *button;
IBOutlet UISlider *volumeslider;
NSTimer *volumetimer;
AVAudioPlayer *audioplayer;
}
-(IBAction) pushplay;
@end
And in .m file,
-(IBAction) pushplay{
//NSError *err;
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
audioplayer = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:filepath] error:NULL];
audioplayer.delegate = self;
[audioplayer play];
volumetimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updatevolume) userInfo:nil repeats:YES];
}
-(void) updatevolume{
[audioplayer setVolume:volumeslider.value];
}
Hope this helps friend.

Pugalmuni
- 9,350
- 8
- 56
- 97

vijay adhikari
- 2,455
- 1
- 16
- 22
-
1How do you think, how many times per second your updatevolume method will be fired? – pronebird May 26 '12 at 12:26