#include "speaker.h"

#import <AVFoundation/AVFoundation.h>
AVAudioPlayer *player;

speaker::speaker(QObject *parent) : QObject(parent)
{}

void speaker::on(void)
{
    #ifdef Q_OS_IOS
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
    #endif
}

void speaker::off(void)
{
    #ifdef Q_OS_IOS
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryRecord error:nil];
    #endif
}

void speaker::play(QByteArray sound)
{
    player = [[AVAudioPlayer alloc] initWithData:sound.toNSData() error:Nil];
    [player play];
}

void speaker::stop(void)
{
    [player stop];
}