Acontece um certo delay quando eu clico em play e pause no celular, e isso, eu acredito, gera um audio duplicado, como se o aplicativo não conseguisse identificar mais o primeiro audio e cria um segundo e assim por diante. Realmente nao sei porque esse erro acontece, segue o código do RadioController.m:
#import "FMRadioViewController.h"
@interface FMRadioViewController ()
@end
NSTimer * playlisRequestTimer;
NSTimer * programmingRequestTimer;
@implementation FMRadioViewController
- (void)viewDidLoad
{
self.screenName = @"FM - IOS";
[self.actualTrack setMarqueeType:MLContinuous];
[self.nextTrack setMarqueeType:MLContinuous];
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playlistRequestSuccessful) name:FMPlaylistRequestSuccessfulNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playlistRequestFailed) name:FMPlaylistRequestFailedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(programacaoRequestSuccessful) name:FMProgramacaoRequestSuccessfulNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(programacaoRequestFailed) name:FMProgramacaoRequestFailedNotification object:nil];
FMSplashViewController * splashViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"splashViewController"];
FMAppDelegate * delegate = [[UIApplication sharedApplication] delegate];
if(delegate.shouldDisplayBannerView){
[self presentViewController:splashViewController animated:NO completion:nil];
delegate.shouldDisplayBannerView = NO;
}
self.playlist = [FMPlaylistController getPlaylist];
[self.actualTrack setTextColor :[UIColor whiteColor]];
[self.nextTrack setTextColor:[UIColor whiteColor]];
if (self.playlist) {
if ([((FMNow *) self.playlist.now).artist isEqualToString:@""]) {
[self.actualTrack setText:@"FM "];
[self.actualArtist setText:@""];
}else{
[self.actualArtist setText:((FMNow *) self.playlist.now).artist];
[self.actualTrack setText:[NSString stringWithFormat:@"%@ ",((FMNow *) self.playlist.now).title]];
}
[self.nextTrack setText:[NSString stringWithFormat:@"%@ - %@ ", ((FMNext *) self.playlist.next).artist, ((FMNext *) self.playlist.next).title]];
}
self.programacao = [FMProgrammingController getProgramacao];
if (self.programacao) {
[self programacaoRequestSuccessful];
}
[self.slider setVolumeThumbImage:[UIImage imageNamed:@"barra"] forState:UIControlStateNormal];
[FMProgrammingController requestProgramacao];
[FMPlaylistController requestPlaylist];
if([[Reachability reachabilityWithHostname:@"www.google.com"] currentReachabilityStatus] == NotReachable) {
self.radioButton.enabled = NO;
} else {
self.radioButton.enabled = YES;
}
[self.actualTrack restartLabel];
[self.nextTrack restartLabel];
[self updatePlayButton];
[self.actualTrack setText: @"FM"];
}
- (IBAction)toggleRadio:(id)sender
{
[[FMRadioController sharedController] initPlay];
[self updatePlayButton];
}
- (IBAction)changeVolumeUp:(id)sender {
self.musicPlayerController = [MPMusicPlayerController applicationMusicPlayer];
self.musicPlayerController.volume = self.musicPlayerController.volume + 0.0625;
}
- (IBAction)changeVolumeDown:(id)sender {
self.musicPlayerController = [MPMusicPlayerController applicationMusicPlayer];
self.musicPlayerController.volume = self.musicPlayerController.volume - 0.0625;
}
- (void) updatePlayButton
{
if ([[FMRadioController sharedController] isPlaying])
self.radioButton.selected = YES;
else
self.radioButton.selected = NO;
}