在Appdelegate.h
我在Appdelegate.h和Appdelegate.m文件中导入了playerviewcontroller.
我在Appdelegate.h和Appdelegate.m文件中导入了playerviewcontroller.
@class PlayerViewController; @property(nonatomic)float volumeDelegate;
在Appdelegate.m
@synthesize volumeDelegate; - (void)volumeChanged:(NSNotification *)notification { volumeDelegate =1.0 PlayerViewController *volumeObject=[[PlayerViewController alloc]init]; [volumeObject setVolumeForAVAudioPlayer]; }
在Playerviewcontroller.h
-(void)setVolumeForAVAudioPlayer;
在Playerviewcontroller.m
@interface PlayerViewController () { AppDelegate *appdelegate; } -(void)viewDidLoad { appdelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; } -(void)setVolumeForAVAudioPlayer { [appdelegate.sharedplayer setVolume:appdelegate.volumeDelegate]; NSLog(@"System Volume in player view: %f",appdelegate.volumeDelegate); }
当我运行这个我得到volumeDelegate值为零如下.
播放器视图中的系统音量:0.000000000
我在这里做的错误是什么
解决方法
在访问该值之前,您是否在下面写下一行,
appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
那么这个电话应该是打电话,
-(void)setVolumeForAVAudioPlayer { [appdelegate.sharedplayer setVolume:appdelegate.volumeDelegate]; NSLog(@"System Volume in player view: %f",appdelegate.volumeDelegate); }