Skip to content

Commit

Permalink
Make NSUInteger to NSInteger, CLose #89
Browse files Browse the repository at this point in the history
  • Loading branch information
saiday committed Aug 17, 2015
1 parent 5ca62da commit 739ae31
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 56 deletions.
45 changes: 42 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
*.xcuserstat
*.xcuserstate
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
.DS_Store

## Other
*.xccheckout
*.moved-aside
*.xcuserstate
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build
14 changes: 7 additions & 7 deletions HyseteriaSamples/HyseteriaSamples/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ @interface ViewController ()
__block NSMutableArray *itunesPreviewUrls;
}

@property (nonatomic) NSUInteger itemsCount;
@property (nonatomic) NSInteger itemsCount;
@property (nonatomic) PlayingType playingType;

@property (nonatomic, weak) IBOutlet UIBarButtonItem *playButton;
Expand Down Expand Up @@ -137,27 +137,27 @@ - (void)hysteriaPlayerRateChanged:(BOOL)isPlaying
NSLog(@"player rate changed");
}

- (void)hysteriaPlayerWillChangedAtIndex:(NSUInteger)index
- (void)hysteriaPlayerWillChangedAtIndex:(NSInteger)index
{
NSLog(@"index: %li is about to play", index);
}

#pragma mark - HysteriaPlayerDataSource

- (NSUInteger)hysteriaPlayerNumberOfItems
- (NSInteger)hysteriaPlayerNumberOfItems
{
return self.itemsCount;
}


/*!
Adopt one of
hysteriaPlayerURLForItemAtIndex:(NSUInteger)index
hysteriaPlayerURLForItemAtIndex:(NSInteger)index
or
hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSUInteger)index
hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSInteger)index
which meets your requirements.
*/
- (NSURL *)hysteriaPlayerURLForItemAtIndex:(NSUInteger)index preBuffer:(BOOL)preBuffer
- (NSURL *)hysteriaPlayerURLForItemAtIndex:(NSInteger)index preBuffer:(BOOL)preBuffer
{
switch (self.playingType) {
case PlayingTypeStaticItems:
Expand All @@ -170,7 +170,7 @@ - (NSURL *)hysteriaPlayerURLForItemAtIndex:(NSUInteger)index preBuffer:(BOOL)pre
}
}

- (void)hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSUInteger)index preBuffer:(BOOL)preBuffer
- (void)hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSInteger)index preBuffer:(BOOL)preBuffer
{
if (self.playingType == PlayingTypeAsync) {
NSString *urlString = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?amgArtistId=468749&entity=song&limit=%lu&sort=recent", (unsigned long) self.itemsCount];
Expand Down
46 changes: 23 additions & 23 deletions HysteriaPlayer/HysteriaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
#import <AvailabilityMacros.h>
#import <AVFoundation/AVFoundation.h>

typedef NS_ENUM(NSUInteger, HysteriaPlayerReadyToPlay) {
typedef NS_ENUM(NSInteger, HysteriaPlayerReadyToPlay) {
HysteriaPlayerReadyToPlayPlayer = 3000,
HysteriaPlayerReadyToPlayCurrentItem = 3001,
};

typedef NS_ENUM(NSUInteger, HysteriaPlayerFailed) {
typedef NS_ENUM(NSInteger, HysteriaPlayerFailed) {
HysteriaPlayerFailedPlayer = 4000,
HysteriaPlayerFailedCurrentItem = 4001,
};
Expand All @@ -43,7 +43,7 @@ typedef NS_ENUM(NSUInteger, HysteriaPlayerFailed) {
@protocol HysteriaPlayerDelegate <NSObject>

@optional
- (void)hysteriaPlayerWillChangedAtIndex:(NSUInteger)index;
- (void)hysteriaPlayerWillChangedAtIndex:(NSInteger)index;
- (void)hysteriaPlayerCurrentItemChanged:(AVPlayerItem *)item;
- (void)hysteriaPlayerRateChanged:(BOOL)isPlaying;
- (void)hysteriaPlayerDidReachEnd;
Expand All @@ -56,41 +56,41 @@ typedef NS_ENUM(NSUInteger, HysteriaPlayerFailed) {
@protocol HysteriaPlayerDataSource <NSObject>

@optional
- (NSUInteger)hysteriaPlayerNumberOfItems;
- (NSInteger)hysteriaPlayerNumberOfItems;
/*!
Recommend you use this method to handle your source getter, setupSourceAsyncGetter:ItemsCount: is for advanced usage.
hysteriaPlayerURLForItemAtIndex:(NSUInteger)index and hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSUInteger)index provides for the use of alternatives.
@method HysteriaPlayerURLForItemAtIndex:(NSUInteger)index
hysteriaPlayerURLForItemAtIndex:(NSInteger)index and hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSInteger)index provides for the use of alternatives.
@method HysteriaPlayerURLForItemAtIndex:(NSInteger)index
*/
- (NSURL *)hysteriaPlayerURLForItemAtIndex:(NSUInteger)index preBuffer:(BOOL)preBuffer;
- (NSURL *)hysteriaPlayerURLForItemAtIndex:(NSInteger)index preBuffer:(BOOL)preBuffer;
/*!
If you are using asynchronously handle your items use this method to tell HysteriaPlayer which URL you would use for index, will excute until you call setupPlayerItemWithUrl:index:
hysteriaPlayerURLForItemAtIndex:(NSUInteger)index and hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSUInteger)index provides for the use of alternatives.
@method HysteriaPlayerAsyncSetUrlForItemAtIndex:(NSUInteger)index
hysteriaPlayerURLForItemAtIndex:(NSInteger)index and hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSInteger)index provides for the use of alternatives.
@method HysteriaPlayerAsyncSetUrlForItemAtIndex:(NSInteger)index
*/
- (void)hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSUInteger)index preBuffer:(BOOL)preBuffer;
- (void)hysteriaPlayerAsyncSetUrlForItemAtIndex:(NSInteger)index preBuffer:(BOOL)preBuffer;

@end

typedef void (^ Failed)(HysteriaPlayerFailed identifier, NSError *error) DEPRECATED_MSG_ATTRIBUTE("deprecated since 2.5 version");
typedef void (^ ReadyToPlay)(HysteriaPlayerReadyToPlay identifier) DEPRECATED_MSG_ATTRIBUTE("deprecated since 2.5 version");
typedef void (^ SourceAsyncGetter)(NSUInteger index) DEPRECATED_MSG_ATTRIBUTE("deprecated since 2.5 version");
typedef NSURL * (^ SourceSyncGetter)(NSUInteger index) DEPRECATED_MSG_ATTRIBUTE("deprecated since 2.5 version");
typedef void (^ SourceAsyncGetter)(NSInteger index) DEPRECATED_MSG_ATTRIBUTE("deprecated since 2.5 version");
typedef NSURL * (^ SourceSyncGetter)(NSInteger index) DEPRECATED_MSG_ATTRIBUTE("deprecated since 2.5 version");

typedef NS_ENUM(NSUInteger, HysteriaPlayerStatus) {
typedef NS_ENUM(NSInteger, HysteriaPlayerStatus) {
HysteriaPlayerStatusPlaying = 0,
HysteriaPlayerStatusForcePause,
HysteriaPlayerStatusBuffering,
HysteriaPlayerStatusUnknown,
};

typedef NS_ENUM(NSUInteger, HysteriaPlayerRepeatMode) {
typedef NS_ENUM(NSInteger, HysteriaPlayerRepeatMode) {
HysteriaPlayerRepeatModeOn = 0,
HysteriaPlayerRepeatModeOnce,
HysteriaPlayerRepeatModeOff,
};

typedef NS_ENUM(NSUInteger, HysteriaPlayerShuffleMode) {
typedef NS_ENUM(NSInteger, HysteriaPlayerShuffleMode) {
HysteriaPlayerShuffleModeOn = 0,
HysteriaPlayerShuffleModeOff,
};
Expand All @@ -99,7 +99,7 @@ typedef NS_ENUM(NSUInteger, HysteriaPlayerShuffleMode) {

@property (nonatomic, weak) id<HysteriaPlayerDelegate> delegate;
@property (nonatomic, weak) id<HysteriaPlayerDataSource> datasource;
@property (nonatomic) NSUInteger itemsCount;
@property (nonatomic) NSInteger itemsCount;
@property (nonatomic) BOOL disableLogs;
@property (nonatomic, strong, readonly) NSArray *playerItems;
@property (nonatomic, readonly) BOOL isInEmptySound;
Expand All @@ -111,25 +111,25 @@ typedef NS_ENUM(NSUInteger, HysteriaPlayerShuffleMode) {
- (void)registerHandlerFailed:(Failed)failed DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDelegate instead");


- (void)setupSourceGetter:(SourceSyncGetter)itemBlock ItemsCount:(NSUInteger) count DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDataSource instead.");
- (void)asyncSetupSourceGetter:(SourceAsyncGetter)asyncBlock ItemsCount:(NSUInteger)count DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDataSource instead.");
- (void)setItemsCount:(NSUInteger)count DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDataSource instead.");
- (void)setupSourceGetter:(SourceSyncGetter)itemBlock ItemsCount:(NSInteger) count DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDataSource instead.");
- (void)asyncSetupSourceGetter:(SourceAsyncGetter)asyncBlock ItemsCount:(NSInteger)count DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDataSource instead.");
- (void)setItemsCount:(NSInteger)count DEPRECATED_MSG_ATTRIBUTE("use HysteriaPlayerDataSource instead.");

/*!
This method is necessary if you setting up AsyncGetter.
After you your AVPlayerItem initialized should call this method on your asyncBlock.
Should not call this method directly if you using setupSourceGetter:ItemsCount.
@method setupPlayerItemWithUrl:index:
*/
- (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSUInteger)index;
- (void)fetchAndPlayPlayerItem: (NSUInteger )startAt;
- (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSInteger)index;
- (void)fetchAndPlayPlayerItem: (NSInteger )startAt;
- (void)removeAllItems;
- (void)removeQueuesAtPlayer;
/*!
Be sure you update hysteriaPlayerNumberOfItems or itemsCount when you remove items
*/
- (void)removeItemAtIndex:(NSUInteger)index;
- (void)moveItemFromIndex:(NSUInteger)from toIndex:(NSUInteger)to;
- (void)removeItemAtIndex:(NSInteger)index;
- (void)moveItemFromIndex:(NSInteger)from toIndex:(NSInteger)to;
- (void)play;
- (void)pause;
- (void)pausePlayerForcibly:(BOOL)forcibly;
Expand Down
46 changes: 23 additions & 23 deletions HysteriaPlayer/HysteriaPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ @interface HysteriaPlayer ()
BOOL isPreBuffered;
BOOL tookAudioFocus;

NSUInteger prepareingItemHash;
NSInteger prepareingItemHash;

UIBackgroundTaskIdentifier bgTaskId;
UIBackgroundTaskIdentifier removedId;
Expand All @@ -31,7 +31,7 @@ @interface HysteriaPlayer ()

@property (nonatomic, strong, readwrite) NSArray *playerItems;
@property (nonatomic, readwrite) BOOL isInEmptySound;
@property (nonatomic) NSUInteger lastItemIndex;
@property (nonatomic) NSInteger lastItemIndex;

@property (nonatomic, strong) AVQueuePlayer *audioPlayer;
@property (nonatomic) HysteriaPlayerRepeatMode repeatMode;
Expand Down Expand Up @@ -101,11 +101,11 @@ - (void)registerHandlerReadyToPlay:(ReadyToPlay)readyToPlay{}

-(void)registerHandlerFailed:(Failed)failed {}

- (void)setupSourceGetter:(SourceSyncGetter)itemBlock ItemsCount:(NSUInteger)count {}
- (void)setupSourceGetter:(SourceSyncGetter)itemBlock ItemsCount:(NSInteger)count {}

- (void)asyncSetupSourceGetter:(SourceAsyncGetter)asyncBlock ItemsCount:(NSUInteger)count{}
- (void)asyncSetupSourceGetter:(SourceAsyncGetter)asyncBlock ItemsCount:(NSInteger)count{}

- (void)setItemsCount:(NSUInteger)count {}
- (void)setItemsCount:(NSInteger)count {}

- (void)playEmptySound
{
Expand Down Expand Up @@ -219,7 +219,7 @@ - (void)AVAudioSessionNotification
#pragma mark =========== Player Methods =========
#pragma mark -

- (void)willPlayPlayerItemAtIndex:(NSUInteger)index
- (void)willPlayPlayerItemAtIndex:(NSInteger)index
{
if (!tookAudioFocus) {
[self preAction];
Expand All @@ -232,7 +232,7 @@ - (void)willPlayPlayerItemAtIndex:(NSUInteger)index
}
}

- (void)fetchAndPlayPlayerItem:(NSUInteger)startAt
- (void)fetchAndPlayPlayerItem:(NSInteger)startAt
{
[self willPlayPlayerItemAtIndex:startAt];
[self.audioPlayer pause];
Expand All @@ -246,15 +246,15 @@ - (void)fetchAndPlayPlayerItem:(NSUInteger)startAt
}
}

- (NSUInteger)hysteriaPlayerItemsCount
- (NSInteger)hysteriaPlayerItemsCount
{
if ([self.datasource respondsToSelector:@selector(hysteriaPlayerNumberOfItems)]) {
return [self.datasource hysteriaPlayerNumberOfItems];
}
return self.itemsCount;
}

- (void)getSourceURLAtIndex:(NSUInteger)index preBuffer:(BOOL)preBuffer
- (void)getSourceURLAtIndex:(NSInteger)index preBuffer:(BOOL)preBuffer
{
NSAssert([self.datasource respondsToSelector:@selector(hysteriaPlayerURLForItemAtIndex:preBuffer:)] || [self.datasource respondsToSelector:@selector(hysteriaPlayerAsyncSetUrlForItemAtIndex:preBuffer:)], @"You didn't implement URL getter delegate from HysteriaPlayerDelegate, hysteriaPlayerURLForItemAtIndex:preBuffer: and hysteriaPlayerAsyncSetUrlForItemAtIndex:preBuffer: provides for the use of alternatives.");
NSAssert([self hysteriaPlayerItemsCount] > index, ([NSString stringWithFormat:@"You are about to access index: %li URL when your HysteriaPlayer items count value is %li, please check hysteriaPlayerNumberOfItems or set itemsCount directly.", (unsigned long)index, (unsigned long)[self hysteriaPlayerItemsCount]]));
Expand All @@ -270,7 +270,7 @@ - (void)getSourceURLAtIndex:(NSUInteger)index preBuffer:(BOOL)preBuffer
}
}

- (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSUInteger)index
- (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSInteger)index
{
AVPlayerItem *item = [AVPlayerItem playerItemWithURL:url];
if (!item)
Expand All @@ -288,7 +288,7 @@ - (void)setupPlayerItemWithUrl:(NSURL *)url index:(NSUInteger)index
}


- (BOOL)findSourceInPlayerItems:(NSUInteger)index
- (BOOL)findSourceInPlayerItems:(NSInteger)index
{
for (AVPlayerItem *item in self.playerItems) {
NSInteger checkIndex = [[self getHysteriaIndex:item] integerValue];
Expand All @@ -308,9 +308,9 @@ - (void)prepareNextPlayerItem
return;
}

NSUInteger nowIndex = self.lastItemIndex;
NSInteger nowIndex = self.lastItemIndex;
BOOL findInPlayerItems = NO;
NSUInteger itemsCount = [self hysteriaPlayerItemsCount];
NSInteger itemsCount = [self hysteriaPlayerItemsCount];

if (nowIndex + 1 < itemsCount) {
findInPlayerItems = [self findSourceInPlayerItems:nowIndex + 1];
Expand Down Expand Up @@ -356,10 +356,10 @@ - (void)removeQueuesAtPlayer
}
}

- (void)removeItemAtIndex:(NSUInteger)order
- (void)removeItemAtIndex:(NSInteger)order
{
for (AVPlayerItem *item in [NSArray arrayWithArray:self.playerItems]) {
NSUInteger CHECK_order = [[self getHysteriaIndex:item] integerValue];
NSInteger CHECK_order = [[self getHysteriaIndex:item] integerValue];
if (CHECK_order == order) {
NSMutableArray *playerItems = [NSMutableArray arrayWithArray:self.playerItems];
[playerItems removeObject:item];
Expand All @@ -374,10 +374,10 @@ - (void)removeItemAtIndex:(NSUInteger)order
}
}

- (void)moveItemFromIndex:(NSUInteger)from toIndex:(NSUInteger)to
- (void)moveItemFromIndex:(NSInteger)from toIndex:(NSInteger)to
{
for (AVPlayerItem *item in self.playerItems) {
NSUInteger CHECK_index = [[self getHysteriaIndex:item] integerValue];
NSInteger CHECK_index = [[self getHysteriaIndex:item] integerValue];
if (CHECK_index == from || CHECK_index == to) {
NSNumber *replaceOrder = CHECK_index == from ? [NSNumber numberWithInteger:to] : [NSNumber numberWithInteger:from];
[self setHysteriaIndex:item Key:replaceOrder];
Expand Down Expand Up @@ -428,7 +428,7 @@ - (void)playNext
}
} else {
NSNumber *nowIndexNumber = [self getHysteriaIndex:self.audioPlayer.currentItem];
NSUInteger nowIndex = nowIndexNumber ? [nowIndexNumber integerValue] : self.lastItemIndex;
NSInteger nowIndex = nowIndexNumber ? [nowIndexNumber integerValue] : self.lastItemIndex;
if (nowIndex + 1 < [self hysteriaPlayerItemsCount]) {
if (self.audioPlayer.items.count > 1) {
[self willPlayPlayerItemAtIndex:nowIndex + 1];
Expand Down Expand Up @@ -592,7 +592,7 @@ - (void)removeTimeObserver:(id)observer
- (void)interruption:(NSNotification*)notification
{
NSDictionary *interuptionDict = notification.userInfo;
NSUInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] integerValue];
NSInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] integerValue];

if (interuptionType == AVAudioSessionInterruptionTypeBegan && !pauseReasonForced) {
interruptedWhilePlaying = YES;
Expand All @@ -611,7 +611,7 @@ - (void)interruption:(NSNotification*)notification
- (void)routeChange:(NSNotification *)notification
{
NSDictionary *routeChangeDict = notification.userInfo;
NSUInteger routeChangeType = [[routeChangeDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];
NSInteger routeChangeType = [[routeChangeDict valueForKey:AVAudioSessionRouteChangeReasonKey] integerValue];

if (routeChangeType == AVAudioSessionRouteChangeReasonOldDeviceUnavailable && !pauseReasonForced) {
routeChangedWhilePlaying = YES;
Expand Down Expand Up @@ -785,17 +785,17 @@ - (void)playerItemDidReachEnd:(NSNotification *)notification
}
}

- (NSUInteger)randomIndex
- (NSInteger)randomIndex
{
NSUInteger itemsCount = [self hysteriaPlayerItemsCount];
NSInteger itemsCount = [self hysteriaPlayerItemsCount];
if ([self.playedItems count] == itemsCount) {
self.playedItems = [NSMutableSet set];
if (_repeatMode == HysteriaPlayerRepeatModeOff) {
return NSNotFound;
}
}

NSUInteger index;
NSInteger index;
do {
index = arc4random() % itemsCount;
} while ([_playedItems containsObject:[NSNumber numberWithInteger:index]]);
Expand Down

0 comments on commit 739ae31

Please sign in to comment.