//
//  AllzicCustomApplication.m
//  Allzic
//
//  Created by Alia Bourouis on 02/07/14.
//  Copyright (c) 2014 Alia Bourouis. All rights reserved.
//

#import "AllzicCustomApplication.h"

@implementation AllzicCustomApplication

#define remoteControlPlayButtonTapped  @"remoteControlPlayButtonTapped"
#define remoteControlPauseButtonTapped  @"remoteControlPauseButtonTapped"
#define remoteControlStopButtonTapped  @"remoteControlStopButtonTapped"
#define remoteControlForwardButtonTapped  @"remoteControlForwardButtonTapped"
#define remoteControlBackwardButtonTapped  @"remoteControlBackwardButtonTapped"
#define remoteControlOtherButtonTapped  @"remoteControlOtherButtonTapped"
#define remoteControlTogglePlayPauseButtonTapped  @"remoteControlTogglePlayPauseButtonTapped"

- (BOOL)canBecomeFirstResponder
{
    return YES;
}


- (void)remoteControlReceivedWithEvent:(UIEvent *)event
{
    switch (event.subtype) {
        case UIEventSubtypeRemoteControlPlay:
            [self postNotificationWithName:remoteControlPlayButtonTapped];
            break;
        case UIEventSubtypeRemoteControlPause:
            [self postNotificationWithName:remoteControlPauseButtonTapped];
            break;
        case UIEventSubtypeRemoteControlStop:
            [self postNotificationWithName:remoteControlStopButtonTapped];
            break;
        case UIEventSubtypeRemoteControlNextTrack:
            [self postNotificationWithName:remoteControlForwardButtonTapped];
            break;
        case UIEventSubtypeRemoteControlPreviousTrack:
            [self postNotificationWithName:remoteControlBackwardButtonTapped];
            break;
        case UIEventSubtypeRemoteControlTogglePlayPause:
            [self postNotificationWithName:remoteControlTogglePlayPauseButtonTapped];
            break;
        default:
            [self postNotificationWithName:remoteControlOtherButtonTapped];
            break;
    }
}

- (void)postNotificationWithName:(NSString *)name
{
    [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil];
}


@end
