Skip to content

Commit

Permalink
SGTrack: Add get functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
libobjc committed Nov 13, 2019
1 parent e1cb725 commit c3a752b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
20 changes: 20 additions & 0 deletions SGPlayer/Classes/Core/SGAsset/SGTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
#import <Foundation/Foundation.h>
#import "SGDefines.h"

@class SGTrack;

/*!
@abstract
Get track with index.
*/
SGTrack *SGTrackWithIndex(NSArray<SGTrack *> *tracks, NSInteger index);

/*!
@abstract
Get track with media type.
*/
SGTrack *SGTrackWithType(NSArray<SGTrack *> *tracks, SGMediaType type);

/*!
@abstract
Get tracks with media types.
*/
NSArray<SGTrack *> *SGTracksWithType(NSArray<SGTrack *> *tracks, SGMediaType type);

@interface SGTrack : NSObject <NSCopying>

+ (instancetype)new NS_UNAVAILABLE;
Expand Down
31 changes: 31 additions & 0 deletions SGPlayer/Classes/Core/SGAsset/SGTrack.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,37 @@
#import "SGTrack.h"
#import "SGTrack+Internal.h"

SGTrack *SGTrackWithIndex(NSArray<SGTrack *> *tracks, NSInteger index)
{
for (SGTrack *obj in tracks) {
if (obj.index == index) {
return obj;
}
}
return nil;
}

SGTrack *SGTrackWithType(NSArray<SGTrack *> *tracks, SGMediaType type)
{
for (SGTrack *obj in tracks) {
if (obj.type == type) {
return obj;
}
}
return nil;
}

NSArray<SGTrack *> *SGTracksWithType(NSArray<SGTrack *> *tracks, SGMediaType type)
{
NSMutableArray *array = [NSMutableArray array];
for (SGTrack *obj in tracks) {
if (obj.type == type) {
[array addObject:obj];
}
}
return array.count ? [array copy] : nil;
}

@implementation SGTrack

- (id)copyWithZone:(NSZone *)zone
Expand Down

0 comments on commit c3a752b

Please sign in to comment.