forked from valtech-sd/react-native-video
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c79051
commit 300794d
Showing
8 changed files
with
333 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// CurrentVideos.h | ||
// react-native-video | ||
// | ||
// Created by marcin.dziennik on 9/8/23. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@class RCTVideo; | ||
@interface CurrentVideos : NSObject | ||
+ (instancetype)shared; | ||
- (void)add: (RCTVideo*)video forTag: (NSNumber*)tag; | ||
- (nullable RCTVideo*)videoForTag: (NSNumber*)tag; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// CurrentVideos.m | ||
// react-native-video | ||
// | ||
// Created by marcin.dziennik on 9/8/23. | ||
// | ||
|
||
#import "CurrentVideos.h" | ||
#import "RCTVideo.h" | ||
#import "WeakVideoRef.h" | ||
|
||
@interface CurrentVideos () | ||
@property (strong) NSMutableDictionary <NSNumber*, WeakVideoRef*> *videos; | ||
@end | ||
|
||
@implementation CurrentVideos | ||
|
||
+ (nonnull instancetype)shared { | ||
static CurrentVideos *instance = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
instance = [[self alloc] init]; | ||
}); | ||
return instance; | ||
} | ||
|
||
- (instancetype)init { | ||
if (self = [super init]) { | ||
_videos = [[NSMutableDictionary alloc] init]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)add:(nonnull RCTVideo *)video forTag:(nonnull NSNumber *)tag { | ||
[self cleanup]; | ||
WeakVideoRef *ref = [[WeakVideoRef alloc] init]; | ||
ref.video = video; | ||
[_videos setObject:ref forKey:tag]; | ||
} | ||
|
||
|
||
- (nullable RCTVideo *)videoForTag:(nonnull NSNumber *)tag { | ||
[self cleanup]; | ||
return [[_videos objectForKey:tag] video]; | ||
} | ||
|
||
- (void)cleanup { | ||
for (NSNumber* key in [_videos allKeys]) { | ||
if (_videos[key].video == nil) { | ||
[_videos removeObjectForKey:key]; | ||
} | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.