【发布时间】:2011-04-01 06:01:29
【问题描述】:
我有播放 iPod 库中歌曲的应用程序,我还必须在后台播放歌曲,所以我使用 avplayer。但我没有设置它的音量。是他们设置音量的任何方式。
【问题讨论】:
标签: iphone
我有播放 iPod 库中歌曲的应用程序,我还必须在后台播放歌曲,所以我使用 avplayer。但我没有设置它的音量。是他们设置音量的任何方式。
【问题讨论】:
标签: iphone
带有音量滑块的通知弹出窗口 - 希望这会有所帮助:
- (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];
}
【讨论】:
您无法使用AVAudioPlayer 播放 ipod-Library 曲目。 AVAssetExportSession 在 IOS.5 中有一个 BUG,所以它无法从 mainbundle 中的 iPod 库中导出,所以如果你想播放 iPod 曲目,你坚持使用 AVPlayer。遗憾的是,只有硬件按钮可以控制音量。
【讨论】:
请检查Adjusting the volume of a playing AVPlayer
如果你可以使用AVAudioPlayer,你可以很容易地使用它的属性volume
【讨论】:
要使用滑块并使用此代码,
在.h文件中写下这段代码,别忘了实现AVAudio框架,
#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
在 .m 文件中,
-(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];
}
希望对朋友有帮助。
【讨论】: