How to Prevent a warning
Hi i keep getting this warning when i try to build th project
warning: conditional expression of distinct Objective-C types 'UIImage*' and 'UIButton*' lacks a cast
is there any thing i can do about it?
#import "avTouchController.h"
#include "CALevelMeter.h"
// amount to skip on rewind or fast forward
#define SKIP_TIME 1.0
// amount to play between skips
#define SKIP_INTERVAL .2
@implementation avTouchController
@synthesize fileName;
@synthesize playButton;
@synthesize ffwButton;
@synthesize rewButton;
@synthesize volumeSlider;
@synthesize progressBar;
@synthesize currentTime;
@synthesize duration;
@synthesize lvlMeter_in;
@synthesize updateTimer;
@synthesize player;
@synthesize inBackground;
void RouteChangeListener( void * inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void * inData);
-(void)updateCurrentTimeForPlayer:(AVAudioPlayer *)p
{
currentTime.text = [NSString stringWithFormat:@"%d:%02d", (int)p.currentTime / 60, (int)p.currentTime % 60, nil];
progressBar.value = p.currentTime;
}
- (void)updateCurrentTime
{
[self updateCurrentTimeForPlayer:self.player];
}
- (void)updateViewForPlayerState:(AVAudioPlayer *)p
{
[self updateCurrentTimeForPlayer:p];
if (updateTimer)
[updateTimer invalidate];
if (p.playing)
{
[playButton setImage:((p.playing == YES) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal];
[lvlMeter_in setPlayer:p];
updateTimer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateCurrentTime) userInfo:p repeats:YES];
}
else
{
[playButton setImage:((p.playing == YES) ? pauseBtnBG : playBtnBG) forState:UIControlStateNormal];
[lvlMeter_in setPlayer:nil];
updateTimer = nil;
}
}
- (void)updateViewForPlayerStateInBackground:(AVAudioPlayer *)p
{
[self updateCurrentTimeForPlayer:p];
if (p.playing)
{
[playButton setImage:((p.playing == YES) ? rewButton : playBtnBG) forState:UIControlStateNormal]; (this is where i have problems)
}
else
{
[playButton setImage:((p.playing == YES) ? rewButton : playBtnBG) forState:UIControlStateNormal];
}
}
-(void)updateViewForPlayerInfo:(AVAudioPlayer*)p
{
duration.text = [NSString stringWithFormat:@"%d:%02d", (int)p.duration / 60, (int)p.duration % 60, nil];
progressBar.maximumValue = p.duration;
volumeSlider.value = p.volume;
}
- (void)rewind
{
AVAudioPlayer *p = rewTimer.userInfo;
p.currentTime-= SKIP_TIME;
[self updateCurrentTimeForPlayer:p];
}
- (void)ffwd
{
AVAudioPlayer *p = ffwTimer.userInfo;
p.currentTime+= SKIP_TIME;
[self updateCurrentTimeForPlayer:p];
}
- (void)awakeFromNib
{
// Make the array to store our AVAudioPlayer objects
soundFiles = [[NSMutableArray alloc] initWithCapacity:3];
playBtnBG = [[UIImage imageNamed:@"play.png"] retain];
pauseBtnBG = [[UIImage imageNamed:@"pause.png"] retain];
rewButton = [[UIImage imageNamed:@"rewind.png"] retain];
[playButton setImage:playBtnBG forState:UIControlStateNormal];
[self registerForBackgroundNotifications];
updateTimer = nil;
rewTimer = nil;
ffwTimer = nil;
duration.adjustsFontSizeToFitWidth = YES;
currentTime.adjustsFontSizeToFitWidth = YES;
progressBar.minimumValue = 0.0;
// Load the array with the sample file
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: [[NSBundle mainBundle] pathForResource:@"My Song" ofType:@"mp3"]];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
if (self.player)
{
fileName.text = [NSString stringWithFormat: @"%@ (%d ch.)", [[player.url relativePath] lastPathComponent], player.numberOfChannels, nil];
[self updateViewForPlayerInfo:player];
[self updateViewForPlayerState:player];
player.numberOfLoops = 0;
player.delegate = self;
}
OSStatus result = AudioSessionInitialize(NULL, NULL, NULL, NULL);
if (result)
NSLog(@"Error initializing audio session! %d", result);
[[AVAudioSession sharedInstance] setDelegate: self];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
if (setCategoryError)
NSLog(@"Error setting category! %d", setCategoryError);
result = AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, RouteChangeListener, self);
if (result)
NSLog(@"Could not add property listener! %d", result);
[fileURL release];
}
-(void)pausePlaybackForPlayer:(AVAudioPlayer*)p
{
[p pause];
[self updateViewForPlayerState:p];
}
-(void)startPlaybackForPlayer:(AVAudioPlayer*)p
{
if ([p play])
{
[self updateViewForPlayerState:p];
}
else
NSLog(@"Could not play %@\n", p.url);
}
- (IBAction)playButtonPressed:(UIButton *)sender
{
if (player.playing == YES)
[self pausePlaybackForPlayer: player];
else
[self startPlaybackForPlayer: player];
}
- (IBAction)rewButtonPressed:(UIButton *)sender
{
if (rewTimer) [rewTimer invalidate];
rewTimer = [NSTimer scheduledTimerWithTimeInterval:SKIP_INTERVAL target:self selector:@selector(rewind) userInfo:player repeats:YES];
}
- (IBAction)rewButtonReleased:(UIButton *)sender
{
if (rewTimer) [rewTimer invalidate];
rewTimer = nil;
}
- (IBAction)ffwButtonPressed:(UIButton *)sender
{
if (ffwTimer) [ffwTimer invalidate];
ffwTimer = [NSTimer scheduledTimerWithTimeInterval:SKIP_INTERVAL target:self selector:@selector(ffwd) userInfo:player repeats:YES];
}
- (IBAction)ffwButtonReleased:(UIButton *)sender
{
if (ffwTimer) [ffwTimer invalidate];
ffwTimer = nil;
}
开发者_如何学Python- (IBAction)volumeSliderMoved:(UISlider *)sender
{
player.volume = [sender value];
}
- (IBAction)progressSliderMoved:(UISlider *)sender
{
player.currentTime = sender.value;
[self updateCurrentTimeForPlayer:player];
}
- (void)dealloc
{
[super dealloc];
[fileName release];
[playButton release];
[ffwButton release];
[rewButton release];
[volumeSlider release];
[progressBar release];
[currentTime release];
[duration release];
[lvlMeter_in release];
[updateTimer release];
[player release];
[playBtnBG release];
[pauseBtnBG release];
}
#pragma mark AudioSession handlers
void RouteChangeListener( void * inClientData,
AudioSessionPropertyID inID,
UInt32 inDataSize,
const void * inData)
{
avTouchController* This = (avTouchController*)inClientData;
if (inID == kAudioSessionProperty_AudioRouteChange) {
CFDictionaryRef routeDict = (CFDictionaryRef)inData;
NSNumber* reasonValue = (NSNumber*)CFDictionaryGetValue(routeDict, CFSTR(kAudioSession_AudioRouteChangeKey_Reason));
int reason = [reasonValue intValue];
if (reason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {
[This pausePlaybackForPlayer:This.player];
}
}
}
#pragma mark AVAudioPlayer delegate methods
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)p successfully:(BOOL)flag
{
if (flag == NO)
NSLog(@"Playback finished unsuccessfully");
[p setCurrentTime:0.];
[self updateViewForPlayerState:p];
}
- (void)playerDecodeErrorDidOccur:(AVAudioPlayer *)p error:(NSError *)error
{
NSLog(@"ERROR IN DECODE: %@\n", error);
}
// we will only get these notifications if playback was interrupted
- (void)audioPlayerBeginInterruption:(AVAudioPlayer *)p
{
NSLog(@"Interruption begin. Updating UI for new state");
// the object has already been paused, we just need to update UI
if (inBackground)
{
[self updateViewForPlayerStateInBackground:p];
}
else
{
[self updateViewForPlayerState:p];
}
}
- (void)audioPlayerEndInterruption:(AVAudioPlayer *)p
{
NSLog(@"Interruption ended. Resuming playback");
[self startPlaybackForPlayer:p];
}
#pragma mark background notifications
- (void)registerForBackgroundNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(setInBackgroundFlag)
name:UIApplicationWillResignActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(clearInBackgroundFlag)
name:UIApplicationWillEnterForegroundNotification
object:nil];
}
- (void)setInBackgroundFlag
{
inBackground = true;
}
- (void)clearInBackgroundFlag
{
inBackground = false;
}
@end
EDIT: I have already tried RewBtnBG but it says not declared in this scope. Any thing to fix that?
[playButton setImage:((p.playing == YES) ? rewButton : playBtnBG) forState:UIControlStateNormal];
newButton is a UIButton and playBtnBG is a UIImage I guess. Possibly you really wanted (guesssing from your naming conventions for other images).
[playButton setImage:((p.playing == YES) ? rewBtnBG : playBtnBG) forState:UIControlStateNormal];
精彩评论