1
0
mirror of https://github.com/thes3m/XNI synced 2024-12-26 13:26:06 +01:00
Matej Jan 74ccf177c5 Adding missing folders
git-svn-id: http://xni.googlecode.com/svn/XNI@55 ac433895-eea3-a490-d80a-17149a75e588
2011-02-01 15:47:13 +00:00

87 lines
1.3 KiB
Objective-C

//
// MediaQueue.m
// XNI
//
// Created by Matej Jan on 18.1.11.
// Copyright 2011 Retronator. All rights reserved.
//
#import "MediaQueue.h"
#import <AVFoundation/AVFoundation.h>
#import "MediaQueue+Internal.h"
#import "Song+Internal.h"
@implementation MediaQueue
- (id) init
{
self = [super init];
if (self != nil) {
queue = [[NSMutableArray alloc] init];
activeSongChanged = [[Event alloc] init];
}
return self;
}
@synthesize activeSongIndex;
- (Event *) activeSongChanged {
return activeSongChanged;
}
- (void) setActiveSongIndex:(int)value {
if (value == activeSongIndex) {
return;
}
AVAudioPlayer *player = self.activeSong.audioPlayer;
BOOL playing = player.playing;
if (playing) {
// Stop playing current song.
[player pause];
player.currentTime = 0;
}
activeSongIndex = value;
if (playing) {
// Start new song.
[self.activeSong.audioPlayer play];
}
[activeSongChanged raiseWithSender:self];
}
- (Song *) activeSong {
return [queue objectAtIndex:activeSongIndex];
}
- (int) count {
return [queue count];
}
- (Song *) itemAt:(int)index {
return [queue objectAtIndex:index];
}
- (void) setSong:(Song *)song {
[queue removeAllObjects];
[queue addObject:song];
activeSongIndex = 0;
}
- (void) dealloc
{
[activeSongChanged release];
[queue release];
[super dealloc];
}
@end