![在Xcode当中用slider和switch控件实现音乐的开关和音量控制 在Xcode当中用slider和switch控件实现音乐的开关和音量控制](https://i-blog.csdnimg.cn/blog_migrate/f7739e2daff4a2fca10f75908ea76e91.jpeg)
在AppDelegate.h中
#import
#import
#import "ViewController.h"
@class ViewController;
@interface AppDelegate : UIResponder <</span>UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
在AppDelegate.m中
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
@synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOp
{
}
在ViewController中
#import
#import
@interface ViewController : UIViewController <</span>AVAudioPlayerDelegate>
{
}
//@property
@property(nonatomic,strong)UILabel*label;
@property(nonatomic,strong)UISlider *slider;
@property(nonatomic,strong) UISwitch *Switch;
@property(nonatomic,strong)AVAudioPlayer *player;
@property(nonatomic,strong)IBOutlet UISlider *m_volume;
-(IBAction)sliderChanged:(UISlider*)sender;
//
- (IBAction)musicSwitch:(id)sender;
-(IBAction)changeVolume:(id)sender;
-(void)playAudioFile:(NSString *)soundFileName;
@end
#import "ViewController.h"
#import "AppDelegate.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize label;
@synthesize slider;
@synthesize Switch;
@synthesize player;
@synthesize m_volume;
- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
}
//让tabel里面的数字由1到100内增减
-(IBAction)sliderChanged:(UISlider*)sender
{
}
//[[NSNotificationCenter defaultCenter] addObserver:self
//selector:@selector(volumeChanged:)
//name:@"AVSystemController_SystemVolumeDidChangeNot
//object:nil];
//实现协议方法
-(void)audioPlayerBeginInterrup
{
}
//实现协议方法
-(void)audioPlayerEndInterrupti
{
}
//播放音乐
-(void)playAudioFile:(NSString *)soundFileName{
}
- (IBAction)musicSwitch:(id)sender
{
}
-(IBAction)changeVolume:(id)sender
{
}
@end