Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se

Solucionado (ver solução)

Audio duplicado

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;
}
3 respostas

Continuação do RadioController.m:

-(void) playlistRequestSuccessful
{
    if(!playlisRequestTimer.isValid) {

        playlisRequestTimer = [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(requestPlaylist) userInfo:nil repeats:NO];

    }

    self.playlist = [FMPlaylistController getPlaylist];

    if ([((FMNow *) self.playlist.now).artist isEqualToString:@""])
        self.youreListening.hidden = YES;
    else
        self.youreListening.hidden = NO;

    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]];

}

-(void) playlistRequestFailed
{
    [self.actualTrack setText:@"FM"];
    [self.actualArtist setText:@""];

    if(!playlisRequestTimer.isValid) {

        [self requestPlaylist];

    }

}

-(void) programacaoRequestSuccessful
{
    [programmingRequestTimer invalidate];

    NSString * hourString = [NSString stringWithFormat:@"%@ hs às %@ hs", [FMProgrammingController getCurrentProgram].hour, [FMProgrammingController getNextProgramHour]];

    self.programacao = [FMProgrammingController getProgramacao];

    if([FMProgrammingController getCurrentProgram].hour && [FMProgrammingController getNextProgramHour]) {

         [self.programHour setText:hourString];

    }

    [self.programName setText:[FMProgrammingController getCurrentProgram].name];
    if(![[FMProgrammingController getCurrentProgram].speaker isEqualToString:@""])
        [self.programPresenter setText:[FMProgrammingController getCurrentProgram].speaker];
    else
        [self.programPresenter setText:@" "];
}


-(void) programacaoRequestFailed
{
    if(!programmingRequestTimer.isValid) {

        programmingRequestTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(requestProgramacao) userInfo:nil repeats:YES];

    }
}

-(void) requestPlaylist
{
    [FMPlaylistController requestPlaylist];
}

-(void) requestProgramacao
{
    [FMProgrammingController requestProgramacao];
}

-(void)viewWillAppear:(BOOL)animated
{
    [self updatePlayButton];
}

- (void) reachabilityHasChanged
{
    [super reachabilityHasChanged];

    if([[Reachability reachabilityWithHostname:@"www.google.com"] currentReachabilityStatus] == NotReachable) {
        self.radioButton.enabled = NO;
        self.youreListening.enabled = NO;
        NSLog(@"FMRadioViewController: Sem internet - Desabilitando os botões da rádio");
    } else {
        self.radioButton.enabled = YES;
        self.youreListening.enabled = YES;
        NSLog(@"FMRadioViewController: Internet Reestabelecida - Habilitando os botões da rádio");
    }
}

//-(void)viewDidAppear:(BOOL)animated
//{
//    self.screenName = @"Ao Vivo";
//}

@end

RadioController.h:

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
#import "FMSplashViewController.h"
#import "FMAppDelegate.h"
#import "FMRadioController.h"
#import "FMPlaylistController.h"
#import "FMNow.h"
#import "FMNext.h"
#import "FMProgramming.h"
#import "FMProgrammingController.h"
#import "FMSideBarTableViewController.h"
#import "FMConfigController.h"
#import "FMConfig.h"
#import "MarqueeLabel.h"

@interface FMRadioViewController : FMViewController

@property BOOL shouldShowBannerScreen;

@property (strong, nonatomic) FMPlaylist * playlist;

@property (strong, nonatomic) NSMutableArray * programacao;

@property (weak, nonatomic) IBOutlet UILabel *youreListening;

@property (strong, nonatomic) IBOutlet UIButton *radioButton;
@property (strong, nonatomic) IBOutlet UILabel *actualArtist;
@property (strong, nonatomic) IBOutlet MarqueeLabel *actualTrack;

@property (strong, nonatomic) IBOutlet MarqueeLabel *nextTrack;

@property (weak, nonatomic) IBOutlet MPVolumeView *slider;

@property (weak, nonatomic) IBOutlet UILabel *programName;

@property (weak, nonatomic) IBOutlet UILabel *programPresenter;

@property (weak, nonatomic) IBOutlet UILabel *programHour;

@property (strong, nonatomic) MPMusicPlayerController * musicPlayerController;

-(void) requestPlaylist;
- (IBAction)toggleRadio:(id)sender;

- (IBAction)changeVolumeUp:(id)sender;
- (IBAction)changeVolumeDown:(id)sender;

@end
solução

Deu certo galera, o problema era outro em outro lugar.