2017-01-11 05:43:43 -07:00
# import < React / RCTConvert . h >
2015-03-30 23:07:55 -06:00
# import "RCTVideo.h"
2017-01-11 05:43:43 -07:00
# import < React / RCTBridgeModule . h >
# import < React / RCTEventDispatcher . h >
# import < React / UIView + React . h >
2018-06-21 10:08:37 -06:00
# include < MediaAccessibility / MediaAccessibility . h >
# include < AVFoundation / AVFoundation . h >
2015-03-30 23:07:55 -06:00
2015-04-08 00:49:14 -06:00
static NSString * const statusKeyPath = @ "status" ;
2015-08-05 06:52:30 -06:00
static NSString * const playbackLikelyToKeepUpKeyPath = @ "playbackLikelyToKeepUp" ;
2016-02-18 17:45:09 -07:00
static NSString * const playbackBufferEmptyKeyPath = @ "playbackBufferEmpty" ;
2016-04-28 06:25:45 -06:00
static NSString * const readyForDisplayKeyPath = @ "readyForDisplay" ;
2016-04-28 06:29:09 -06:00
static NSString * const playbackRate = @ "rate" ;
2017-02-13 19:38:02 -07:00
static NSString * const timedMetadata = @ "timedMetadata" ;
2018-09-13 06:06:12 -06:00
static NSString * const externalPlaybackActive = @ "externalPlaybackActive" ;
2015-04-08 00:49:14 -06:00
2018-07-29 18:42:09 -06:00
static int const RCTVideoUnset = -1 ;
2018-08-08 16:37:18 -06:00
# ifdef DEBUG
# define DebugLog ( . . . ) NSLog ( __VA _ARGS __ )
# else
# define DebugLog ( . . . ) ( void ) 0
# endif
2015-03-30 23:07:55 -06:00
@ implementation RCTVideo
{
2015-04-07 16:24:49 -06:00
AVPlayer * _player ;
2015-04-08 00:49:14 -06:00
AVPlayerItem * _playerItem ;
2018-12-13 20:30:38 -07:00
NSDictionary * _source ;
2015-08-05 06:52:30 -06:00
BOOL _playerItemObserversSet ;
2016-02-18 17:45:09 -07:00
BOOL _playerBufferEmpty ;
2015-04-07 16:24:49 -06:00
AVPlayerLayer * _playerLayer ;
2018-07-09 12:20:32 -06:00
BOOL _playerLayerObserverSet ;
2018-10-07 21:24:50 -06:00
RCTVideoPlayerViewController * _playerViewController ;
2015-04-07 16:24:49 -06:00
NSURL * _videoURL ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
BOOL _requestingCertificate ;
BOOL _requestingCertificateErrored ;
/ * DRM * /
NSDictionary * _drm ;
AVAssetResourceLoadingRequest * _loadingRequest ;
2018-02-28 09:42:49 -07:00
2015-04-07 16:24:49 -06:00
/ * Required to publish events * /
RCTEventDispatcher * _eventDispatcher ;
2016-05-17 01:37:11 -06:00
BOOL _playbackRateObserverRegistered ;
2018-09-13 06:06:12 -06:00
BOOL _isExternalPlaybackActiveObserverRegistered ;
2018-06-25 12:43:51 -06:00
BOOL _videoLoadStarted ;
2018-08-09 10:58:03 -06:00
2015-04-08 16:15:57 -06:00
bool _pendingSeek ;
float _pendingSeekTime ;
float _lastSeekTime ;
2018-02-28 09:42:49 -07:00
2015-04-07 16:24:49 -06:00
/ * For sending videoProgress events * /
2015-12-22 16:39:04 -07:00
Float64 _progressUpdateInterval ;
BOOL _controls ;
id _timeObserver ;
2018-02-28 09:42:49 -07:00
2015-04-07 21:38:16 -06:00
/ * Keep track of any modifiers , need to be applied after each play * /
float _volume ;
float _rate ;
2018-11-26 15:50:31 -07:00
float _maxBitRate ;
2018-10-29 10:53:52 -06:00
2019-08-22 02:10:39 -06:00
BOOL _automaticallyWaitsToMinimizeStalling ;
2015-04-07 21:38:16 -06:00
BOOL _muted ;
2015-05-10 17:01:25 -06:00
BOOL _paused ;
2015-06-16 02:07:50 -06:00
BOOL _repeat ;
2018-06-05 19:40:12 -06:00
BOOL _allowsExternalPlayback ;
2018-06-21 10:08:37 -06:00
NSArray * _textTracks ;
2018-06-02 03:24:13 -06:00
NSDictionary * _selectedTextTrack ;
2018-07-17 15:14:21 -06:00
NSDictionary * _selectedAudioTrack ;
2016-04-28 06:38:21 -06:00
BOOL _playbackStalled ;
2015-10-30 03:34:54 -06:00
BOOL _playInBackground ;
2020-06-16 06:31:23 -06:00
BOOL _preventsDisplaySleepDuringVideoPlayback ;
2020-05-15 01:25:19 -06:00
float _preferredForwardBufferDuration ;
2016-04-29 05:55:34 -06:00
BOOL _playWhenInactive ;
2018-11-26 15:23:04 -07:00
BOOL _pictureInPicture ;
2017-04-20 12:10:06 -06:00
NSString * _ignoreSilentSwitch ;
2020-04-20 14:25:59 -06:00
NSString * _mixWithOthers ;
2015-06-16 02:07:50 -06:00
NSString * _resizeMode ;
2018-08-02 11:32:50 -06:00
BOOL _fullscreen ;
2018-10-18 16:21:46 -06:00
BOOL _fullscreenAutorotate ;
2018-10-07 21:24:50 -06:00
NSString * _fullscreenOrientation ;
2016-04-01 06:55:23 -06:00
BOOL _fullscreenPlayerPresented ;
2018-11-06 07:38:28 -07:00
NSString * _filterName ;
2018-12-13 20:30:38 -07:00
BOOL _filterEnabled ;
2016-03-31 12:34:22 -06:00
UIViewController * _presentingViewController ;
2018-07-18 18:06:09 -06:00
# if __has _include ( < react - native - video / RCTVideoCache . h > )
2018-03-01 15:38:38 -07:00
RCTVideoCache * _videoCache ;
2018-07-18 18:06:09 -06:00
# endif
2019-03-11 20:55:36 -06:00
# if TARGET_OS _IOS
void ( ^ __strong _Nonnull _restoreUserInterfaceForPIPStopCompletionHandler ) ( BOOL ) ;
AVPictureInPictureController * _pipController ;
# endif
2015-03-30 23:07:55 -06:00
}
2015-05-30 13:50:45 -06:00
- ( instancetype ) initWithEventDispatcher : ( RCTEventDispatcher * ) eventDispatcher
{
2015-03-30 23:07:55 -06:00
if ( ( self = [ super init ] ) ) {
2015-04-06 13:17:32 -06:00
_eventDispatcher = eventDispatcher ;
2019-08-30 08:01:19 -06:00
_automaticallyWaitsToMinimizeStalling = YES ;
2016-05-17 01:37:11 -06:00
_playbackRateObserverRegistered = NO ;
2018-09-13 06:06:12 -06:00
_isExternalPlaybackActiveObserverRegistered = NO ;
2016-04-28 06:38:21 -06:00
_playbackStalled = NO ;
2015-04-08 11:34:27 -06:00
_rate = 1.0 ;
_volume = 1.0 ;
2015-06-16 22:14:14 -06:00
_resizeMode = @ "AVLayerVideoGravityResizeAspectFill" ;
2018-10-18 16:21:46 -06:00
_fullscreenAutorotate = YES ;
2018-10-09 17:01:41 -06:00
_fullscreenOrientation = @ "all" ;
2015-04-08 16:15:57 -06:00
_pendingSeek = false ;
_pendingSeekTime = 0.0 f ;
_lastSeekTime = 0.0 f ;
2015-12-22 16:39:04 -07:00
_progressUpdateInterval = 250 ;
_controls = NO ;
2016-02-18 17:45:09 -07:00
_playerBufferEmpty = YES ;
2016-06-01 23:58:38 -06:00
_playInBackground = false ;
2020-06-16 06:31:23 -06:00
_preventsDisplaySleepDuringVideoPlayback = true ;
2020-05-15 01:25:19 -06:00
_preferredForwardBufferDuration = 0.0 f ;
2018-06-10 10:04:13 -06:00
_allowsExternalPlayback = YES ;
2016-04-29 05:55:34 -06:00
_playWhenInactive = false ;
2019-03-11 20:55:36 -06:00
_pictureInPicture = false ;
2017-04-20 12:10:06 -06:00
_ignoreSilentSwitch = @ "inherit" ; // inherit , ignore , obey
2020-04-20 14:25:59 -06:00
_mixWithOthers = @ "inherit" ; // inherit , mix , duck
2019-03-11 20:55:36 -06:00
# if TARGET_OS _IOS
_restoreUserInterfaceForPIPStopCompletionHandler = NULL ;
# endif
2018-07-18 18:06:09 -06:00
# if __has _include ( < react - native - video / RCTVideoCache . h > )
2018-03-01 15:38:38 -07:00
_videoCache = [ RCTVideoCache sharedInstance ] ;
2018-07-18 18:06:09 -06:00
# endif
2015-06-25 16:40:46 -06:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self
2015-08-05 06:52:30 -06:00
selector : @ selector ( applicationWillResignActive : )
name : UIApplicationWillResignActiveNotification
object : nil ] ;
2018-02-28 09:42:49 -07:00
2016-04-29 01:46:28 -06:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( applicationDidEnterBackground : )
name : UIApplicationDidEnterBackgroundNotification
object : nil ] ;
2018-02-28 09:42:49 -07:00
2015-06-25 16:40:46 -06:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self
2015-08-05 06:52:30 -06:00
selector : @ selector ( applicationWillEnterForeground : )
name : UIApplicationWillEnterForegroundNotification
object : nil ] ;
2018-08-09 10:58:03 -06:00
2018-07-12 22:48:58 -06:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( audioRouteChanged : )
name : AVAudioSessionRouteChangeNotification
object : nil ] ;
2015-03-30 23:07:55 -06:00
}
2018-02-28 09:42:49 -07:00
2015-03-30 23:07:55 -06:00
return self ;
}
2018-10-07 21:24:50 -06:00
- ( RCTVideoPlayerViewController * ) createPlayerViewController : ( AVPlayer * ) player
withPlayerItem : ( AVPlayerItem * ) playerItem {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
RCTVideoPlayerViewController * viewController = [ [ RCTVideoPlayerViewController alloc ] init ] ;
viewController . showsPlaybackControls = YES ;
viewController . rctDelegate = self ;
viewController . preferredOrientation = _fullscreenOrientation ;
viewController . view . frame = self . bounds ;
viewController . player = player ;
return viewController ;
2015-12-22 16:39:04 -07:00
}
/ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* * Get the duration for a AVPlayerItem .
* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * /
- ( CMTime ) playerItemDuration
{
2018-02-28 09:42:49 -07:00
AVPlayerItem * playerItem = [ _player currentItem ] ;
if ( playerItem . status = = AVPlayerItemStatusReadyToPlay )
{
return ( [ playerItem duration ] ) ;
}
return ( kCMTimeInvalid ) ;
2015-12-22 16:39:04 -07:00
}
2016-09-06 20:23:13 -06:00
- ( CMTimeRange ) playerItemSeekableTimeRange
{
2018-02-28 09:42:49 -07:00
AVPlayerItem * playerItem = [ _player currentItem ] ;
if ( playerItem . status = = AVPlayerItemStatusReadyToPlay )
{
return [ playerItem seekableTimeRanges ] . firstObject . CMTimeRangeValue ;
}
return ( kCMTimeRangeZero ) ;
2016-09-06 20:23:13 -06:00
}
2017-09-28 19:37:26 -06:00
- ( void ) addPlayerTimeObserver
{
const Float64 progressUpdateIntervalMS = _progressUpdateInterval / 1000 ;
2018-05-29 17:11:15 -06:00
// @ see endScrubbing in AVPlayerDemoPlaybackViewController . m
// of https : // developer . apple . com / library / ios / samplecode / AVPlayerDemo / Introduction / Intro . html
2017-09-28 19:37:26 -06:00
__weak RCTVideo * weakSelf = self ;
_timeObserver = [ _player addPeriodicTimeObserverForInterval : CMTimeMakeWithSeconds ( progressUpdateIntervalMS , NSEC_PER _SEC )
queue : NULL
usingBlock : ^ ( CMTime time ) { [ weakSelf sendProgressUpdate ] ; }
] ;
}
2015-12-22 16:39:04 -07:00
/ * Cancels the previously registered time observer . * /
- ( void ) removePlayerTimeObserver
{
2018-02-28 09:42:49 -07:00
if ( _timeObserver )
{
[ _player removeTimeObserver : _timeObserver ] ;
_timeObserver = nil ;
}
2015-12-22 16:39:04 -07:00
}
# pragma mark - Progress
2015-06-26 12:41:41 -06:00
- ( void ) dealloc
{
2015-08-05 06:52:30 -06:00
[ [ NSNotificationCenter defaultCenter ] removeObserver : self ] ;
2017-06-09 15:31:46 -06:00
[ self removePlayerLayer ] ;
2018-03-19 13:56:55 -06:00
[ self removePlayerItemObservers ] ;
2016-08-04 06:32:04 -06:00
[ _player removeObserver : self forKeyPath : playbackRate context : nil ] ;
2019-02-14 08:34:14 -07:00
[ _player removeObserver : self forKeyPath : externalPlaybackActive context : nil ] ;
2015-06-26 12:41:41 -06:00
}
2015-06-25 16:40:46 -06:00
# pragma mark - App lifecycle handlers
- ( void ) applicationWillResignActive : ( NSNotification * ) notification
{
2016-04-29 05:55:34 -06:00
if ( _playInBackground || _playWhenInactive || _paused ) return ;
2018-02-28 09:42:49 -07:00
2016-04-29 05:55:34 -06:00
[ _player pause ] ;
[ _player setRate : 0.0 ] ;
2015-06-25 16:40:46 -06:00
}
2016-04-29 01:46:28 -06:00
- ( void ) applicationDidEnterBackground : ( NSNotification * ) notification
{
2016-06-01 23:58:38 -06:00
if ( _playInBackground ) {
// Needed to play sound in background . See https : // developer . apple . com / library / ios / qa / qa1668 / _index . html
[ _playerLayer setPlayer : nil ] ;
2019-06-10 11:00:03 -06:00
[ _playerViewController setPlayer : nil ] ;
2016-06-01 23:58:38 -06:00
}
2016-04-29 01:46:28 -06:00
}
2015-06-25 16:40:46 -06:00
- ( void ) applicationWillEnterForeground : ( NSNotification * ) notification
{
[ self applyModifiers ] ;
2016-04-28 07:06:22 -06:00
if ( _playInBackground ) {
[ _playerLayer setPlayer : _player ] ;
2019-06-10 11:00:03 -06:00
[ _playerViewController setPlayer : _player ] ;
2016-04-28 07:06:22 -06:00
}
2015-06-25 16:40:46 -06:00
}
2018-07-12 22:48:58 -06:00
# pragma mark - Audio events
- ( void ) audioRouteChanged : ( NSNotification * ) notification
{
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSNumber * reason = [ [ notification userInfo ] objectForKey : AVAudioSessionRouteChangeReasonKey ] ;
NSNumber * previousRoute = [ [ notification userInfo ] objectForKey : AVAudioSessionRouteChangePreviousRouteKey ] ;
if ( reason . unsignedIntValue = = AVAudioSessionRouteChangeReasonOldDeviceUnavailable ) {
self . onVideoAudioBecomingNoisy ( @ { @ "target" : self . reactTag } ) ;
}
2018-07-12 22:48:58 -06:00
}
2015-04-08 09:46:13 -06:00
# pragma mark - Progress
2015-05-30 13:50:45 -06:00
- ( void ) sendProgressUpdate
{
2018-02-28 09:42:49 -07:00
AVPlayerItem * video = [ _player currentItem ] ;
if ( video = = nil || video . status ! = AVPlayerItemStatusReadyToPlay ) {
return ;
}
CMTime playerDuration = [ self playerItemDuration ] ;
if ( CMTIME_IS _INVALID ( playerDuration ) ) {
return ;
}
CMTime currentTime = _player . currentTime ;
2020-05-15 01:25:19 -06:00
NSDate * currentPlaybackTime = _player . currentItem . currentDate ;
2018-02-28 09:42:49 -07:00
const Float64 duration = CMTimeGetSeconds ( playerDuration ) ;
const Float64 currentTimeSecs = CMTimeGetSeconds ( currentTime ) ;
[ [ NSNotificationCenter defaultCenter ] postNotificationName : @ "RCTVideo_progress" object : nil userInfo : @ { @ "progress" : [ NSNumber numberWithDouble : currentTimeSecs / duration ] } ] ;
if ( currentTimeSecs >= 0 && self . onVideoProgress ) {
self . onVideoProgress ( @ {
@ "currentTime" : [ NSNumber numberWithFloat : CMTimeGetSeconds ( currentTime ) ] ,
@ "playableDuration" : [ self calculatePlayableDuration ] ,
@ "atValue" : [ NSNumber numberWithLongLong : currentTime . value ] ,
@ "atTimescale" : [ NSNumber numberWithInt : currentTime . timescale ] ,
2020-05-15 01:25:19 -06:00
@ "currentPlaybackTime" : [ NSNumber numberWithLongLong : [ @ ( floor ( [ currentPlaybackTime timeIntervalSince1970 ] * 1000 ) ) longLongValue ] ] ,
2018-02-28 09:42:49 -07:00
@ "target" : self . reactTag ,
@ "seekableDuration" : [ self calculateSeekableDuration ] ,
} ) ;
}
2015-04-06 14:05:05 -06:00
}
2015-06-10 15:29:38 -06:00
/ * !
* Calculates and returns the playable duration of the current player item using its loaded time ranges .
*
2015-06-11 19:11:55 -06:00
* \ returns The playable duration of the current player item in seconds .
2015-06-10 15:29:38 -06:00
* /
2015-08-05 06:52:30 -06:00
- ( NSNumber * ) calculatePlayableDuration
{
2015-06-10 15:29:38 -06:00
AVPlayerItem * video = _player . currentItem ;
if ( video . status = = AVPlayerItemStatusReadyToPlay ) {
__block CMTimeRange effectiveTimeRange ;
[ video . loadedTimeRanges enumerateObjectsUsingBlock : ^ ( id obj , NSUInteger idx , BOOL * stop ) {
CMTimeRange timeRange = [ obj CMTimeRangeValue ] ;
if ( CMTimeRangeContainsTime ( timeRange , video . currentTime ) ) {
effectiveTimeRange = timeRange ;
* stop = YES ;
}
} ] ;
2015-06-17 23:08:01 -06:00
Float64 playableDuration = CMTimeGetSeconds ( CMTimeRangeGetEnd ( effectiveTimeRange ) ) ;
if ( playableDuration > 0 ) {
return [ NSNumber numberWithFloat : playableDuration ] ;
}
2015-06-10 15:29:38 -06:00
}
2015-06-17 23:08:01 -06:00
return [ NSNumber numberWithInteger : 0 ] ;
2015-06-10 15:29:38 -06:00
}
2017-09-06 19:12:34 -06:00
- ( NSNumber * ) calculateSeekableDuration
{
2018-02-28 09:42:49 -07:00
CMTimeRange timeRange = [ self playerItemSeekableTimeRange ] ;
if ( CMTIME_IS _NUMERIC ( timeRange . duration ) )
{
return [ NSNumber numberWithFloat : CMTimeGetSeconds ( timeRange . duration ) ] ;
}
return [ NSNumber numberWithInteger : 0 ] ;
2017-09-06 19:12:34 -06:00
}
2015-08-05 06:52:30 -06:00
- ( void ) addPlayerItemObservers
2015-05-30 13:47:14 -06:00
{
[ _playerItem addObserver : self forKeyPath : statusKeyPath options : 0 context : nil ] ;
2016-02-18 17:45:09 -07:00
[ _playerItem addObserver : self forKeyPath : playbackBufferEmptyKeyPath options : 0 context : nil ] ;
2015-08-05 06:52:30 -06:00
[ _playerItem addObserver : self forKeyPath : playbackLikelyToKeepUpKeyPath options : 0 context : nil ] ;
2017-02-13 19:38:02 -07:00
[ _playerItem addObserver : self forKeyPath : timedMetadata options : NSKeyValueObservingOptionNew context : nil ] ;
2015-08-05 06:52:30 -06:00
_playerItemObserversSet = YES ;
2015-05-30 13:47:14 -06:00
}
/ * Fixes https : // github . com / brentvatne / react - native - video / issues / 43
* Crashes caused when trying to remove the observer when there is no
* observer set * /
2015-08-05 06:52:30 -06:00
- ( void ) removePlayerItemObservers
2015-05-30 13:47:14 -06:00
{
2015-08-05 06:52:30 -06:00
if ( _playerItemObserversSet ) {
2015-05-30 13:47:14 -06:00
[ _playerItem removeObserver : self forKeyPath : statusKeyPath ] ;
2016-02-18 17:45:09 -07:00
[ _playerItem removeObserver : self forKeyPath : playbackBufferEmptyKeyPath ] ;
2015-08-05 06:52:30 -06:00
[ _playerItem removeObserver : self forKeyPath : playbackLikelyToKeepUpKeyPath ] ;
2017-02-13 19:38:02 -07:00
[ _playerItem removeObserver : self forKeyPath : timedMetadata ] ;
2015-08-05 06:52:30 -06:00
_playerItemObserversSet = NO ;
2015-05-30 13:47:14 -06:00
}
}
2015-04-08 09:46:13 -06:00
# pragma mark - Player and source
2015-05-30 13:50:45 -06:00
- ( void ) setSrc : ( NSDictionary * ) source
{
2018-12-13 20:30:38 -07:00
_source = source ;
2018-03-19 13:56:55 -06:00
[ self removePlayerLayer ] ;
2015-12-22 16:39:04 -07:00
[ self removePlayerTimeObserver ] ;
2015-08-05 06:52:30 -06:00
[ self removePlayerItemObservers ] ;
2018-08-08 16:37:18 -06:00
dispatch_after ( dispatch_time ( DISPATCH_TIME _NOW , ( int64_t ) 0 ) , dispatch_get _main _queue ( ) , ^ {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-06-21 10:08:37 -06:00
// perform on next run loop , otherwise other passed react - props may not be set
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
[ self playerItemForSource : self -> _source withCallback : ^ ( AVPlayerItem * playerItem ) {
self -> _playerItem = playerItem ;
2018-07-17 07:29:53 -06:00
_playerItem = playerItem ;
2020-05-15 01:25:19 -06:00
[ self setPreferredForwardBufferDuration : _preferredForwardBufferDuration ] ;
2018-07-17 06:36:03 -06:00
[ self addPlayerItemObservers ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
[ self setFilter : self -> _filterName ] ;
[ self setMaxBitRate : self -> _maxBitRate ] ;
2018-07-17 06:36:03 -06:00
[ _player pause ] ;
if ( _playbackRateObserverRegistered ) {
[ _player removeObserver : self forKeyPath : playbackRate context : nil ] ;
_playbackRateObserverRegistered = NO ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
if ( self -> _isExternalPlaybackActiveObserverRegistered ) {
[ self -> _player removeObserver : self forKeyPath : externalPlaybackActive context : nil ] ;
self -> _isExternalPlaybackActiveObserverRegistered = NO ;
2018-09-13 06:06:12 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
self -> _player = [ AVPlayer playerWithPlayerItem : self -> _playerItem ] ;
2021-06-03 07:11:57 -06:00
[ self applyModifiers ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
self -> _player . actionAtItemEnd = AVPlayerActionAtItemEndNone ;
[ self -> _player addObserver : self forKeyPath : playbackRate options : 0 context : nil ] ;
self -> _playbackRateObserverRegistered = YES ;
[ self -> _player addObserver : self forKeyPath : externalPlaybackActive options : 0 context : nil ] ;
self -> _isExternalPlaybackActiveObserverRegistered = YES ;
2018-07-17 06:36:03 -06:00
[ self addPlayerTimeObserver ] ;
2019-08-30 08:01:19 -06:00
if ( @ available ( iOS 10.0 , * ) ) {
[ self setAutomaticallyWaitsToMinimizeStalling : _automaticallyWaitsToMinimizeStalling ] ;
}
2018-06-21 10:08:37 -06:00
2018-07-17 06:36:03 -06:00
// Perform on next run loop , otherwise onVideoLoadStart is nil
2018-08-08 16:37:18 -06:00
if ( self . onVideoLoadStart ) {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
id uri = [ self -> _source objectForKey : @ "uri" ] ;
id type = [ self -> _source objectForKey : @ "type" ] ;
2018-07-17 06:36:03 -06:00
self . onVideoLoadStart ( @ { @ "src" : @ {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
@ "uri" : uri ? uri : [ NSNull null ] ,
@ "type" : type ? type : [ NSNull null ] ,
@ "isNetwork" : [ NSNumber numberWithBool : ( bool ) [ self -> _source objectForKey : @ "isNetwork" ] ] } ,
@ "drm" : self -> _drm ? self -> _drm : [ NSNull null ] ,
@ "target" : self . reactTag
2018-07-17 06:36:03 -06:00
} ) ;
}
} ] ;
2016-12-12 17:16:11 -07:00
} ) ;
2018-06-25 12:43:51 -06:00
_videoLoadStarted = YES ;
2015-04-08 00:49:14 -06:00
}
2015-04-07 09:31:40 -06:00
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
- ( void ) setDrm : ( NSDictionary * ) drm {
_drm = drm ;
}
2018-06-21 10:08:37 -06:00
- ( NSURL * ) urlFilePath : ( NSString * ) filepath {
2018-08-01 13:15:27 -06:00
if ( [ filepath containsString : @ "file://" ] ) {
return [ NSURL URLWithString : filepath ] ;
}
2018-06-21 10:08:37 -06:00
2018-08-20 12:52:06 -06:00
// if no file found , check if the file exists in the Document directory
2018-08-01 13:15:27 -06:00
NSArray * paths = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES ) ;
2018-06-21 10:08:37 -06:00
NSString * relativeFilePath = [ filepath lastPathComponent ] ;
// the file may be multiple levels below the documents directory
NSArray * fileComponents = [ filepath componentsSeparatedByString : @ "Documents/" ] ;
2018-09-04 16:44:19 -06:00
if ( fileComponents . count > 1 ) {
2018-06-21 10:08:37 -06:00
relativeFilePath = [ fileComponents objectAtIndex : 1 ] ;
}
NSString * path = [ paths . firstObject stringByAppendingPathComponent : relativeFilePath ] ;
if ( [ [ NSFileManager defaultManager ] fileExistsAtPath : path ] ) {
return [ NSURL fileURLWithPath : path ] ;
}
return nil ;
}
2018-08-08 16:37:18 -06:00
- ( void ) playerItemPrepareText : ( AVAsset * ) asset assetOptions : ( NSDictionary * __nullable ) assetOptions withCallback : ( void ( ^ ) ( AVPlayerItem * ) ) handler
2015-05-30 13:50:45 -06:00
{
2018-10-18 16:21:46 -06:00
if ( ! _textTracks || _textTracks . count = = 0 ) {
2018-08-27 19:05:41 -06:00
handler ( [ AVPlayerItem playerItemWithAsset : asset ] ) ;
return ;
2018-07-09 17:28:38 -06:00
}
2018-10-18 16:21:46 -06:00
// AVPlayer can ' t airplay AVMutableCompositions
_allowsExternalPlayback = NO ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-07-09 17:28:38 -06:00
// sideload text tracks
2018-06-21 10:08:37 -06:00
AVMutableComposition * mixComposition = [ [ AVMutableComposition alloc ] init ] ;
2018-07-09 17:28:38 -06:00
AVAssetTrack * videoAsset = [ asset tracksWithMediaType : AVMediaTypeVideo ] . firstObject ;
AVMutableCompositionTrack * videoCompTrack = [ mixComposition addMutableTrackWithMediaType : AVMediaTypeVideo preferredTrackID : kCMPersistentTrackID_Invalid ] ;
2018-06-21 10:08:37 -06:00
[ videoCompTrack insertTimeRange : CMTimeRangeMake ( kCMTimeZero , videoAsset . timeRange . duration )
2018-07-09 17:28:38 -06:00
ofTrack : videoAsset
atTime : kCMTimeZero
error : nil ] ;
2018-08-09 10:58:03 -06:00
2018-07-09 17:28:38 -06:00
AVAssetTrack * audioAsset = [ asset tracksWithMediaType : AVMediaTypeAudio ] . firstObject ;
AVMutableCompositionTrack * audioCompTrack = [ mixComposition addMutableTrackWithMediaType : AVMediaTypeAudio preferredTrackID : kCMPersistentTrackID_Invalid ] ;
2018-06-21 10:08:37 -06:00
[ audioCompTrack insertTimeRange : CMTimeRangeMake ( kCMTimeZero , videoAsset . timeRange . duration )
2018-07-09 17:28:38 -06:00
ofTrack : audioAsset
atTime : kCMTimeZero
error : nil ] ;
2018-08-09 10:58:03 -06:00
2018-07-31 17:56:19 -06:00
NSMutableArray * validTextTracks = [ NSMutableArray array ] ;
2018-07-09 17:28:38 -06:00
for ( int i = 0 ; i < _textTracks . count ; + + i ) {
AVURLAsset * textURLAsset ;
NSString * textUri = [ _textTracks objectAtIndex : i ] [ @ "uri" ] ;
if ( [ [ textUri lowercaseString ] hasPrefix : @ "http" ] ) {
textURLAsset = [ AVURLAsset URLAssetWithURL : [ NSURL URLWithString : textUri ] options : assetOptions ] ;
} else {
textURLAsset = [ AVURLAsset URLAssetWithURL : [ self urlFilePath : textUri ] options : nil ] ;
}
AVAssetTrack * textTrackAsset = [ textURLAsset tracksWithMediaType : AVMediaTypeText ] . firstObject ;
2018-07-31 17:56:19 -06:00
if ( ! textTrackAsset ) continue ; // fix when there ' s no textTrackAsset
[ validTextTracks addObject : [ _textTracks objectAtIndex : i ] ] ;
2018-07-09 17:28:38 -06:00
AVMutableCompositionTrack * textCompTrack = [ mixComposition
addMutableTrackWithMediaType : AVMediaTypeText
preferredTrackID : kCMPersistentTrackID_Invalid ] ;
[ textCompTrack insertTimeRange : CMTimeRangeMake ( kCMTimeZero , videoAsset . timeRange . duration )
2018-08-09 10:58:03 -06:00
ofTrack : textTrackAsset
atTime : kCMTimeZero
error : nil ] ;
2018-07-09 17:28:38 -06:00
}
2018-07-31 17:56:19 -06:00
if ( validTextTracks . count ! = _textTracks . count ) {
[ self setTextTracks : validTextTracks ] ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-07-17 05:28:37 -06:00
handler ( [ AVPlayerItem playerItemWithAsset : mixComposition ] ) ;
2015-04-08 00:49:14 -06:00
}
2015-04-07 09:31:40 -06:00
2018-02-28 09:42:49 -07:00
- ( void ) playerItemForSource : ( NSDictionary * ) source withCallback : ( void ( ^ ) ( AVPlayerItem * ) ) handler
2015-05-30 13:50:45 -06:00
{
2015-04-08 11:34:27 -06:00
bool isNetwork = [ RCTConvert BOOL : [ source objectForKey : @ "isNetwork" ] ] ;
bool isAsset = [ RCTConvert BOOL : [ source objectForKey : @ "isAsset" ] ] ;
2019-01-24 05:15:58 -07:00
bool shouldCache = [ RCTConvert BOOL : [ source objectForKey : @ "shouldCache" ] ] ;
2015-04-08 11:34:27 -06:00
NSString * uri = [ source objectForKey : @ "uri" ] ;
NSString * type = [ source objectForKey : @ "type" ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
AVURLAsset * asset ;
2019-02-18 22:34:34 -07:00
if ( ! uri || [ uri isEqualToString : @ "" ] ) {
2018-09-19 04:02:55 -06:00
DebugLog ( @ "Could not find video URL in source '%@'" , source ) ;
return ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-08-08 16:37:18 -06:00
NSURL * url = isNetwork || isAsset
? [ NSURL URLWithString : uri ]
: [ [ NSURL alloc ] initFileURLWithPath : [ [ NSBundle mainBundle ] pathForResource : uri ofType : type ] ] ;
2018-07-17 06:36:03 -06:00
NSMutableDictionary * assetOptions = [ [ NSMutableDictionary alloc ] init ] ;
2018-02-28 09:42:49 -07:00
2016-10-06 15:34:01 -06:00
if ( isNetwork ) {
2020-06-11 08:53:14 -06:00
NSDictionary * headers = [ source objectForKey : @ "requestHeaders" ] ;
if ( [ headers count ] > 0 ) {
[ assetOptions setObject : headers forKey : @ "AVURLAssetHTTPHeaderFieldsKey" ] ;
}
2018-08-27 19:05:41 -06:00
NSArray * cookies = [ [ NSHTTPCookieStorage sharedHTTPCookieStorage ] cookies ] ;
[ assetOptions setObject : cookies forKey : AVURLAssetHTTPCookiesKey ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-07-18 18:06:09 -06:00
# if __has _include ( < react - native - video / RCTVideoCache . h > )
2019-01-24 05:15:58 -07:00
if ( shouldCache && ( ! _textTracks || ! _textTracks . count ) ) {
2018-08-27 19:05:41 -06:00
/ * The DVURLAsset created by cache doesn ' t have a tracksWithMediaType property , so trying
2019-01-24 05:15:58 -07:00
* to bring in the text track code will crash . I suspect this is because the asset hasn ' t fully loaded .
2018-08-27 19:05:41 -06:00
* Until this is fixed , we need to bypass caching when text tracks are specified .
* /
2018-08-27 19:16:59 -06:00
DebugLog ( @ "Caching is not supported for uri '%@' because text tracks are not compatible with the cache. Checkout https://github.com/react-native-community/react-native-video/blob/master/docs/caching.md" , uri ) ;
2018-08-27 19:05:41 -06:00
[ self playerItemForSourceUsingCache : uri assetOptions : assetOptions withCallback : handler ] ;
return ;
}
2018-07-18 18:06:09 -06:00
# endif
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
asset = [ AVURLAsset URLAssetWithURL : url options : assetOptions ] ;
2018-08-08 16:37:18 -06:00
} else if ( isAsset ) {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
asset = [ AVURLAsset URLAssetWithURL : url options : nil ] ;
} else {
asset = [ AVURLAsset URLAssetWithURL : [ [ NSURL alloc ] initFileURLWithPath : [ [ NSBundle mainBundle ] pathForResource : uri ofType : type ] ] options : nil ] ;
2015-04-08 11:34:27 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
// Reset _loadingRequest
if ( _loadingRequest ! = nil ) {
[ _loadingRequest finishLoading ] ;
}
_requestingCertificate = NO ;
_requestingCertificateErrored = NO ;
// End Reset _loadingRequest
if ( self -> _drm ! = nil ) {
dispatch_queue _t queue = dispatch_queue _create ( "assetQueue" , nil ) ;
[ asset . resourceLoader setDelegate : self queue : queue ] ;
}
2018-07-17 06:36:03 -06:00
[ self playerItemPrepareText : asset assetOptions : assetOptions withCallback : handler ] ;
2015-04-08 11:34:27 -06:00
}
2018-08-08 16:37:18 -06:00
# if __has _include ( < react - native - video / RCTVideoCache . h > )
- ( void ) playerItemForSourceUsingCache : ( NSString * ) uri assetOptions : ( NSDictionary * ) options withCallback : ( void ( ^ ) ( AVPlayerItem * ) ) handler {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSURL * url = [ NSURL URLWithString : uri ] ;
[ _videoCache getItemForUri : uri withCallback : ^ ( RCTVideoCacheStatus videoCacheStatus , AVAsset * _Nullable cachedAsset ) {
switch ( videoCacheStatus ) {
case RCTVideoCacheStatusMissingFileExtension : {
DebugLog ( @ "Could not generate cache key for uri '%@'. It is currently not supported to cache urls that do not include a file extension. The video file will not be cached. Checkout https://github.com/react-native-community/react-native-video/blob/master/docs/caching.md" , uri ) ;
AVURLAsset * asset = [ AVURLAsset URLAssetWithURL : url options : options ] ;
[ self playerItemPrepareText : asset assetOptions : options withCallback : handler ] ;
return ;
}
case RCTVideoCacheStatusUnsupportedFileExtension : {
DebugLog ( @ "Could not generate cache key for uri '%@'. The file extension of that uri is currently not supported. The video file will not be cached. Checkout https://github.com/react-native-community/react-native-video/blob/master/docs/caching.md" , uri ) ;
AVURLAsset * asset = [ AVURLAsset URLAssetWithURL : url options : options ] ;
[ self playerItemPrepareText : asset assetOptions : options withCallback : handler ] ;
return ;
}
default :
if ( cachedAsset ) {
DebugLog ( @ "Playing back uri '%@' from cache" , uri ) ;
// See note in playerItemForSource about not being able to support text tracks & caching
handler ( [ AVPlayerItem playerItemWithAsset : cachedAsset ] ) ;
return ;
2018-08-08 16:37:18 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
}
DVURLAsset * asset = [ [ DVURLAsset alloc ] initWithURL : url options : options networkTimeout : 10000 ] ;
asset . loaderDelegate = self ;
/ * More granular code to have control over the DVURLAsset
DVAssetLoaderDelegate * resourceLoaderDelegate = [ [ DVAssetLoaderDelegate alloc ] initWithURL : url ] ;
resourceLoaderDelegate . delegate = self ;
NSURLComponents * components = [ [ NSURLComponents alloc ] initWithURL : url resolvingAgainstBaseURL : NO ] ;
components . scheme = [ DVAssetLoaderDelegate scheme ] ;
AVURLAsset * asset = [ [ AVURLAsset alloc ] initWithURL : [ components URL ] options : options ] ;
[ asset . resourceLoader setDelegate : resourceLoaderDelegate queue : dispatch_get _main _queue ( ) ] ;
* /
handler ( [ AVPlayerItem playerItemWithAsset : asset ] ) ;
} ] ;
2018-08-08 16:37:18 -06:00
}
# pragma mark - DVAssetLoaderDelegate
- ( void ) dvAssetLoaderDelegate : ( DVAssetLoaderDelegate * ) loaderDelegate
didLoadData : ( NSData * ) data
forURL : ( NSURL * ) url {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
[ _videoCache storeItem : data forUri : [ url absoluteString ] withCallback : ^ ( BOOL success ) {
DebugLog ( @ "Cache data stored successfully 🎉" ) ;
} ] ;
2015-04-08 11:34:27 -06:00
}
2018-08-08 16:37:18 -06:00
# endif
2015-05-30 13:50:45 -06:00
- ( void ) observeValueForKeyPath : ( NSString * ) keyPath ofObject : ( id ) object change : ( NSDictionary * ) change context : ( void * ) context
{
2019-07-02 14:35:36 -06:00
2019-06-19 07:18:25 -06:00
if ( [ keyPath isEqualToString : readyForDisplayKeyPath ] && [ change objectForKey : NSKeyValueChangeNewKey ] && self . onReadyForDisplay ) {
self . onReadyForDisplay ( @ { @ "target" : self . reactTag } ) ;
return ;
}
2018-06-25 12:43:51 -06:00
if ( object = = _playerItem ) {
2017-02-13 19:38:02 -07:00
// When timeMetadata is read the event onTimedMetadata is triggered
2018-06-25 12:43:51 -06:00
if ( [ keyPath isEqualToString : timedMetadata ] ) {
NSArray < AVMetadataItem * > * items = [ change objectForKey : @ "new" ] ;
if ( items && ! [ items isEqual : [ NSNull null ] ] && items . count > 0 ) {
NSMutableArray * array = [ NSMutableArray new ] ;
for ( AVMetadataItem * item in items ) {
2018-07-09 17:28:38 -06:00
NSString * value = ( NSString * ) item . value ;
2018-06-25 12:43:51 -06:00
NSString * identifier = item . identifier ;
if ( ! [ value isEqual : [ NSNull null ] ] ) {
NSDictionary * dictionary = [ [ NSDictionary alloc ] initWithObjects : @ [ value , identifier ] forKeys : @ [ @ "value" , @ "identifier" ] ] ;
[ array addObject : dictionary ] ;
}
2017-02-13 19:38:02 -07:00
}
2018-06-25 12:43:51 -06:00
self . onTimedMetadata ( @ {
@ "target" : self . reactTag ,
@ "metadata" : array
} ) ;
}
2017-02-13 19:38:02 -07:00
}
2018-06-25 12:43:51 -06:00
2015-08-05 06:52:30 -06:00
if ( [ keyPath isEqualToString : statusKeyPath ] ) {
// Handle player item status change .
if ( _playerItem . status = = AVPlayerItemStatusReadyToPlay ) {
float duration = CMTimeGetSeconds ( _playerItem . asset . duration ) ;
2018-06-25 12:43:51 -06:00
2015-08-05 06:52:30 -06:00
if ( isnan ( duration ) ) {
duration = 0.0 ;
}
2018-06-25 12:43:51 -06:00
2016-04-08 03:10:22 -06:00
NSObject * width = @ "undefined" ;
NSObject * height = @ "undefined" ;
2016-05-01 08:41:30 -06:00
NSString * orientation = @ "undefined" ;
2018-06-25 12:43:51 -06:00
2016-04-08 03:10:22 -06:00
if ( [ _playerItem . asset tracksWithMediaType : AVMediaTypeVideo ] . count > 0 ) {
2016-05-01 09:26:56 -06:00
AVAssetTrack * videoTrack = [ [ _playerItem . asset tracksWithMediaType : AVMediaTypeVideo ] objectAtIndex : 0 ] ;
width = [ NSNumber numberWithFloat : videoTrack . naturalSize . width ] ;
height = [ NSNumber numberWithFloat : videoTrack . naturalSize . height ] ;
CGAffineTransform preferredTransform = [ videoTrack preferredTransform ] ;
2018-06-25 12:43:51 -06:00
2016-05-01 09:26:56 -06:00
if ( ( videoTrack . naturalSize . width = = preferredTransform . tx
2018-06-25 12:43:51 -06:00
&& videoTrack . naturalSize . height = = preferredTransform . ty )
|| ( preferredTransform . tx = = 0 && preferredTransform . ty = = 0 ) )
2016-05-01 09:26:56 -06:00
{
2016-05-01 08:41:30 -06:00
orientation = @ "landscape" ;
2018-06-25 12:43:51 -06:00
} else {
2016-05-01 08:41:30 -06:00
orientation = @ "portrait" ;
2018-06-25 12:43:51 -06:00
}
2020-05-05 09:49:42 -06:00
} else if ( _playerItem . presentationSize . height ) {
width = [ NSNumber numberWithFloat : _playerItem . presentationSize . width ] ;
height = [ NSNumber numberWithFloat : _playerItem . presentationSize . height ] ;
2020-05-05 10:10:49 -06:00
orientation = _playerItem . presentationSize . width > _playerItem . presentationSize . height ? @ "landscape" : @ "portrait" ;
2016-04-08 03:10:22 -06:00
}
2020-05-07 02:58:20 -06:00
if ( _pendingSeek ) {
[ self setCurrentTime : _pendingSeekTime ] ;
_pendingSeek = false ;
}
2018-06-25 12:43:51 -06:00
if ( self . onVideoLoad && _videoLoadStarted ) {
2017-01-16 09:27:08 -07:00
self . onVideoLoad ( @ { @ "duration" : [ NSNumber numberWithFloat : duration ] ,
@ "currentTime" : [ NSNumber numberWithFloat : CMTimeGetSeconds ( _playerItem . currentTime ) ] ,
@ "canPlayReverse" : [ NSNumber numberWithBool : _playerItem . canPlayReverse ] ,
@ "canPlayFastForward" : [ NSNumber numberWithBool : _playerItem . canPlayFastForward ] ,
@ "canPlaySlowForward" : [ NSNumber numberWithBool : _playerItem . canPlaySlowForward ] ,
@ "canPlaySlowReverse" : [ NSNumber numberWithBool : _playerItem . canPlaySlowReverse ] ,
@ "canStepBackward" : [ NSNumber numberWithBool : _playerItem . canStepBackward ] ,
@ "canStepForward" : [ NSNumber numberWithBool : _playerItem . canStepForward ] ,
@ "naturalSize" : @ {
2018-06-25 12:43:51 -06:00
@ "width" : width ,
@ "height" : height ,
@ "orientation" : orientation
} ,
2018-07-17 15:14:21 -06:00
@ "audioTracks" : [ self getAudioTrackInfo ] ,
2018-06-11 21:55:23 -06:00
@ "textTracks" : [ self getTextTrackInfo ] ,
2017-01-16 09:27:08 -07:00
@ "target" : self . reactTag } ) ;
2018-06-25 12:43:51 -06:00
}
_videoLoadStarted = NO ;
2015-08-05 06:52:30 -06:00
[ self attachListeners ] ;
[ self applyModifiers ] ;
2018-06-25 12:43:51 -06:00
} else if ( _playerItem . status = = AVPlayerItemStatusFailed && self . onVideoError ) {
2016-12-12 17:16:11 -07:00
self . onVideoError ( @ { @ "error" : @ { @ "code" : [ NSNumber numberWithInteger : _playerItem . error . code ] ,
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
@ "localizedDescription" : [ _playerItem . error localizedDescription ] = = nil ? @ "" : [ _playerItem . error localizedDescription ] ,
@ "localizedFailureReason" : [ _playerItem . error localizedFailureReason ] = = nil ? @ "" : [ _playerItem . error localizedFailureReason ] ,
@ "localizedRecoverySuggestion" : [ _playerItem . error localizedRecoverySuggestion ] = = nil ? @ "" : [ _playerItem . error localizedRecoverySuggestion ] ,
@ "domain" : _playerItem ! = nil && _playerItem . error ! = nil ? _playerItem . error . domain : @ "RTCVideo" } ,
2018-06-25 12:43:51 -06:00
@ "target" : self . reactTag } ) ;
2015-08-05 06:52:30 -06:00
}
2016-02-18 17:45:09 -07:00
} else if ( [ keyPath isEqualToString : playbackBufferEmptyKeyPath ] ) {
_playerBufferEmpty = YES ;
2017-01-11 05:51:45 -07:00
self . onVideoBuffer ( @ { @ "isBuffering" : @ ( YES ) , @ "target" : self . reactTag } ) ;
2015-08-05 06:52:30 -06:00
} else if ( [ keyPath isEqualToString : playbackLikelyToKeepUpKeyPath ] ) {
// Continue playing ( or not if paused ) after being paused due to hitting an unbuffered zone .
2016-09-19 18:49:12 -06:00
if ( ( ! ( _controls || _fullscreenPlayerPresented ) || _playerBufferEmpty ) && _playerItem . playbackLikelyToKeepUp ) {
2015-08-05 06:52:30 -06:00
[ self setPaused : _paused ] ;
2015-05-11 00:54:58 -06:00
}
2016-02-18 17:45:09 -07:00
_playerBufferEmpty = NO ;
2017-01-11 05:51:45 -07:00
self . onVideoBuffer ( @ { @ "isBuffering" : @ ( NO ) , @ "target" : self . reactTag } ) ;
2015-04-08 00:49:14 -06:00
}
2016-04-28 06:37:45 -06:00
} else if ( object = = _player ) {
2018-06-25 12:43:51 -06:00
if ( [ keyPath isEqualToString : playbackRate ] ) {
if ( self . onPlaybackRateChange ) {
self . onPlaybackRateChange ( @ { @ "playbackRate" : [ NSNumber numberWithFloat : _player . rate ] ,
@ "target" : self . reactTag } ) ;
2016-04-28 06:37:45 -06:00
}
2018-06-25 12:43:51 -06:00
if ( _playbackStalled && _player . rate > 0 ) {
if ( self . onPlaybackResume ) {
self . onPlaybackResume ( @ { @ "playbackRate" : [ NSNumber numberWithFloat : _player . rate ] ,
@ "target" : self . reactTag } ) ;
}
_playbackStalled = NO ;
2016-04-28 06:37:45 -06:00
}
2018-06-25 12:43:51 -06:00
}
2018-09-13 06:06:12 -06:00
else if ( [ keyPath isEqualToString : externalPlaybackActive ] ) {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
if ( self . onVideoExternalPlaybackChange ) {
self . onVideoExternalPlaybackChange ( @ { @ "isExternalPlaybackActive" : [ NSNumber numberWithBool : _player . isExternalPlaybackActive ] ,
@ "target" : self . reactTag } ) ;
}
2018-09-13 06:06:12 -06:00
}
2019-07-02 14:35:36 -06:00
} else if ( object = = _playerViewController . contentOverlayView ) {
// when controls = = true , this is a hack to reset the rootview when rotation happens in fullscreen
if ( [ keyPath isEqualToString : @ "frame" ] ) {
CGRect oldRect = [ change [ NSKeyValueChangeOldKey ] CGRectValue ] ;
CGRect newRect = [ change [ NSKeyValueChangeNewKey ] CGRectValue ] ;
if ( ! CGRectEqualToRect ( oldRect , newRect ) ) {
if ( CGRectEqualToRect ( newRect , [ UIScreen mainScreen ] . bounds ) ) {
NSLog ( @ "in fullscreen" ) ;
2020-02-26 18:43:33 -07:00
[ self . reactViewController . view setFrame : [ UIScreen mainScreen ] . bounds ] ;
[ self . reactViewController . view setNeedsLayout ] ;
} else NSLog ( @ "not fullscreen" ) ;
2019-07-02 14:35:36 -06:00
}
return ;
}
2015-04-08 00:49:14 -06:00
}
2015-03-30 23:07:55 -06:00
}
2015-05-30 13:50:45 -06:00
- ( void ) attachListeners
{
2015-07-18 06:38:56 -06:00
// listen for end of file
2017-10-24 01:47:43 -06:00
[ [ NSNotificationCenter defaultCenter ] removeObserver : self
name : AVPlayerItemDidPlayToEndTimeNotification
object : [ _player currentItem ] ] ;
2015-07-18 06:38:56 -06:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( playerItemDidReachEnd : )
name : AVPlayerItemDidPlayToEndTimeNotification
object : [ _player currentItem ] ] ;
2018-08-09 10:58:03 -06:00
2017-10-24 01:47:43 -06:00
[ [ NSNotificationCenter defaultCenter ] removeObserver : self
name : AVPlayerItemPlaybackStalledNotification
object : nil ] ;
2016-04-28 06:38:21 -06:00
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( playbackStalled : )
name : AVPlayerItemPlaybackStalledNotification
object : nil ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-09-18 08:39:32 -06:00
[ [ NSNotificationCenter defaultCenter ] removeObserver : self
name : AVPlayerItemNewAccessLogEntryNotification
object : nil ] ;
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( handleAVPlayerAccess : )
name : AVPlayerItemNewAccessLogEntryNotification
object : nil ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
[ [ NSNotificationCenter defaultCenter ] removeObserver : self
name : AVPlayerItemFailedToPlayToEndTimeNotification
object : nil ] ;
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( didFailToFinishPlaying : )
name : AVPlayerItemFailedToPlayToEndTimeNotification
object : nil ] ;
2018-09-18 08:39:32 -06:00
}
- ( void ) handleAVPlayerAccess : ( NSNotification * ) notification {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
AVPlayerItemAccessLog * accessLog = [ ( ( AVPlayerItem * ) notification . object ) accessLog ] ;
AVPlayerItemAccessLogEvent * lastEvent = accessLog . events . lastObject ;
/ * TODO : get this working
if ( self . onBandwidthUpdate ) {
self . onBandwidthUpdate ( @ { @ "bitrate" : [ NSNumber numberWithFloat : lastEvent . observedBitrate ] } ) ;
}
* /
}
- ( void ) didFailToFinishPlaying : ( NSNotification * ) notification {
NSError * error = notification . userInfo [ AVPlayerItemFailedToPlayToEndTimeErrorKey ] ;
self . onVideoError ( @ { @ "error" : @ { @ "code" : [ NSNumber numberWithInteger : error . code ] ,
@ "localizedDescription" : [ error localizedDescription ] = = nil ? @ "" : [ error localizedDescription ] ,
@ "localizedFailureReason" : [ error localizedFailureReason ] = = nil ? @ "" : [ error localizedFailureReason ] ,
@ "localizedRecoverySuggestion" : [ error localizedRecoverySuggestion ] = = nil ? @ "" : [ error localizedRecoverySuggestion ] ,
@ "domain" : error . domain } ,
@ "target" : self . reactTag } ) ;
2016-04-28 06:38:21 -06:00
}
- ( void ) playbackStalled : ( NSNotification * ) notification
{
2017-01-16 09:27:08 -07:00
if ( self . onPlaybackStalled ) {
self . onPlaybackStalled ( @ { @ "target" : self . reactTag } ) ;
}
2016-04-28 06:38:21 -06:00
_playbackStalled = YES ;
2015-04-10 20:58:36 -06:00
}
2015-06-26 16:13:03 -06:00
- ( void ) playerItemDidReachEnd : ( NSNotification * ) notification
2015-05-30 13:50:45 -06:00
{
2017-01-16 09:27:08 -07:00
if ( self . onVideoEnd ) {
2018-02-28 09:42:49 -07:00
self . onVideoEnd ( @ { @ "target" : self . reactTag } ) ;
2017-01-16 09:27:08 -07:00
}
2018-02-28 09:42:49 -07:00
2015-06-24 20:09:05 -06:00
if ( _repeat ) {
2015-04-08 11:34:27 -06:00
AVPlayerItem * item = [ notification object ] ;
[ item seekToTime : kCMTimeZero ] ;
[ self applyModifiers ] ;
2018-05-15 23:19:12 -06:00
} else {
[ self removePlayerTimeObserver ] ;
2015-06-24 20:09:05 -06:00
}
2015-04-08 09:46:13 -06:00
}
2015-04-08 11:34:27 -06:00
# pragma mark - Prop setters
2015-04-08 09:46:13 -06:00
2015-05-30 13:50:45 -06:00
- ( void ) setResizeMode : ( NSString * ) mode
{
2015-12-22 16:39:04 -07:00
if ( _controls )
{
_playerViewController . videoGravity = mode ;
}
else
{
_playerLayer . videoGravity = mode ;
}
2015-06-16 02:07:50 -06:00
_resizeMode = mode ;
2015-04-04 18:55:37 -06:00
}
2015-10-30 03:34:54 -06:00
- ( void ) setPlayInBackground : ( BOOL ) playInBackground
{
2016-06-02 00:33:18 -06:00
_playInBackground = playInBackground ;
2015-10-30 03:34:54 -06:00
}
2020-06-16 06:31:23 -06:00
- ( void ) setPreventsDisplaySleepDuringVideoPlayback : ( BOOL ) preventsDisplaySleepDuringVideoPlayback
{
_preventsDisplaySleepDuringVideoPlayback = preventsDisplaySleepDuringVideoPlayback ;
[ self applyModifiers ] ;
}
2018-06-05 19:40:12 -06:00
- ( void ) setAllowsExternalPlayback : ( BOOL ) allowsExternalPlayback
{
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
_allowsExternalPlayback = allowsExternalPlayback ;
_player . allowsExternalPlayback = _allowsExternalPlayback ;
2018-06-05 19:40:12 -06:00
}
2016-04-29 05:55:34 -06:00
- ( void ) setPlayWhenInactive : ( BOOL ) playWhenInactive
{
2016-06-02 00:33:18 -06:00
_playWhenInactive = playWhenInactive ;
2016-04-29 05:55:34 -06:00
}
2018-10-26 14:33:03 -06:00
- ( void ) setPictureInPicture : ( BOOL ) pictureInPicture
{
2019-03-11 20:55:36 -06:00
# if TARGET_OS _IOS
2018-11-26 15:23:04 -07:00
if ( _pictureInPicture = = pictureInPicture ) {
return ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-11-26 15:23:04 -07:00
_pictureInPicture = pictureInPicture ;
if ( _pipController && _pictureInPicture && ! [ _pipController isPictureInPictureActive ] ) {
2018-10-26 14:33:03 -06:00
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
[ _pipController startPictureInPicture ] ;
} ) ;
2018-11-26 15:23:04 -07:00
} else if ( _pipController && ! _pictureInPicture && [ _pipController isPictureInPictureActive ] ) {
2018-10-26 14:33:03 -06:00
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
[ _pipController stopPictureInPicture ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
} ) ;
2018-10-26 14:33:03 -06:00
}
2019-03-11 20:55:36 -06:00
# endif
2018-10-26 14:33:03 -06:00
}
2019-03-11 20:55:36 -06:00
# if TARGET_OS _IOS
2018-10-26 14:33:03 -06:00
- ( void ) setRestoreUserInterfaceForPIPStopCompletionHandler : ( BOOL ) restore
{
if ( _restoreUserInterfaceForPIPStopCompletionHandler ! = NULL ) {
_restoreUserInterfaceForPIPStopCompletionHandler ( restore ) ;
_restoreUserInterfaceForPIPStopCompletionHandler = NULL ;
}
}
- ( void ) setupPipController {
2018-11-26 15:23:04 -07:00
if ( ! _pipController && _playerLayer && [ AVPictureInPictureController isPictureInPictureSupported ] ) {
// Create new controller passing reference to the AVPlayerLayer
_pipController = [ [ AVPictureInPictureController alloc ] initWithPlayerLayer : _playerLayer ] ;
_pipController . delegate = self ;
2018-10-26 14:33:03 -06:00
}
}
2019-03-11 20:55:36 -06:00
# endif
2018-10-26 14:33:03 -06:00
2017-04-20 12:10:06 -06:00
- ( void ) setIgnoreSilentSwitch : ( NSString * ) ignoreSilentSwitch
{
_ignoreSilentSwitch = ignoreSilentSwitch ;
[ self applyModifiers ] ;
}
2020-04-20 14:25:59 -06:00
- ( void ) setMixWithOthers : ( NSString * ) mixWithOthers
{
_mixWithOthers = mixWithOthers ;
[ self applyModifiers ] ;
}
2015-05-30 13:50:45 -06:00
- ( void ) setPaused : ( BOOL ) paused
{
2015-04-07 21:38:16 -06:00
if ( paused ) {
2015-12-22 16:39:04 -07:00
[ _player pause ] ;
2015-07-20 10:46:49 -06:00
[ _player setRate : 0.0 ] ;
2015-04-07 09:31:40 -06:00
} else {
2020-04-20 14:25:59 -06:00
AVAudioSession * session = [ AVAudioSession sharedInstance ] ;
AVAudioSessionCategory category = nil ;
AVAudioSessionCategoryOptions options = nil ;
2017-04-20 12:10:06 -06:00
if ( [ _ignoreSilentSwitch isEqualToString : @ "ignore" ] ) {
2020-04-20 14:25:59 -06:00
category = AVAudioSessionCategoryPlayback ;
2017-04-20 12:10:06 -06:00
} else if ( [ _ignoreSilentSwitch isEqualToString : @ "obey" ] ) {
2020-04-20 14:25:59 -06:00
category = AVAudioSessionCategoryAmbient ;
2017-04-20 12:10:06 -06:00
}
2020-04-20 14:25:59 -06:00
if ( [ _mixWithOthers isEqualToString : @ "mix" ] ) {
options = AVAudioSessionCategoryOptionMixWithOthers ;
} else if ( [ _mixWithOthers isEqualToString : @ "duck" ] ) {
options = AVAudioSessionCategoryOptionDuckOthers ;
}
if ( category ! = nil && options ! = nil ) {
[ session setCategory : category withOptions : options error : nil ] ;
} else if ( category ! = nil && options = = nil ) {
[ session setCategory : category error : nil ] ;
} else if ( category = = nil && options ! = nil ) {
[ session setCategory : session . category withOptions : options error : nil ] ;
}
2019-09-21 23:40:53 -06:00
if ( @ available ( iOS 10.0 , * ) && ! _automaticallyWaitsToMinimizeStalling ) {
[ _player playImmediatelyAtRate : _rate ] ;
} else {
[ _player play ] ;
[ _player setRate : _rate ] ;
}
2015-07-20 10:46:49 -06:00
[ _player setRate : _rate ] ;
2015-04-07 09:31:40 -06:00
}
2018-02-28 09:42:49 -07:00
2015-05-10 17:01:25 -06:00
_paused = paused ;
2015-04-05 11:17:03 -06:00
}
2015-12-22 16:39:04 -07:00
- ( float ) getCurrentTime
{
return _playerItem ! = NULL ? CMTimeGetSeconds ( _playerItem . currentTime ) : 0 ;
}
- ( void ) setCurrentTime : ( float ) currentTime
{
2018-07-09 12:20:32 -06:00
NSDictionary * info = @ {
@ "time" : [ NSNumber numberWithFloat : currentTime ] ,
@ "tolerance" : [ NSNumber numberWithInt : 100 ]
} ;
[ self setSeek : info ] ;
2015-12-22 16:39:04 -07:00
}
2018-07-09 12:20:32 -06:00
- ( void ) setSeek : ( NSDictionary * ) info
2015-05-30 13:50:45 -06:00
{
2018-07-09 12:20:32 -06:00
NSNumber * seekTime = info [ @ "time" ] ;
NSNumber * seekTolerance = info [ @ "tolerance" ] ;
int timeScale = 1000 ;
2015-04-08 16:15:57 -06:00
AVPlayerItem * item = _player . currentItem ;
if ( item && item . status = = AVPlayerItemStatusReadyToPlay ) {
// TODO check loadedTimeRanges
2018-07-09 12:20:32 -06:00
CMTime cmSeekTime = CMTimeMakeWithSeconds ( [ seekTime floatValue ] , timeScale ) ;
2015-04-08 16:15:57 -06:00
CMTime current = item . currentTime ;
// TODO figure out a good tolerance level
2018-07-09 12:20:32 -06:00
CMTime tolerance = CMTimeMake ( [ seekTolerance floatValue ] , timeScale ) ;
2017-03-21 14:25:58 -06:00
BOOL wasPaused = _paused ;
2018-07-09 12:20:32 -06:00
2015-04-08 16:15:57 -06:00
if ( CMTimeCompare ( current , cmSeekTime ) ! = 0 ) {
2017-03-21 14:25:58 -06:00
if ( ! wasPaused ) [ _player pause ] ;
2015-07-18 06:38:56 -06:00
[ _player seekToTime : cmSeekTime toleranceBefore : tolerance toleranceAfter : tolerance completionHandler : ^ ( BOOL finished ) {
2018-05-15 23:19:12 -06:00
if ( ! _timeObserver ) {
[ self addPlayerTimeObserver ] ;
}
2017-09-07 06:16:44 -06:00
if ( ! wasPaused ) {
2018-07-09 12:20:32 -06:00
[ self setPaused : false ] ;
2017-09-07 06:16:44 -06:00
}
2017-01-16 09:27:08 -07:00
if ( self . onVideoSeek ) {
2018-07-09 12:20:32 -06:00
self . onVideoSeek ( @ { @ "currentTime" : [ NSNumber numberWithFloat : CMTimeGetSeconds ( item . currentTime ) ] ,
@ "seekTime" : seekTime ,
@ "target" : self . reactTag } ) ;
2017-01-16 09:27:08 -07:00
}
2015-07-18 06:38:56 -06:00
} ] ;
2018-07-09 12:20:32 -06:00
2015-04-09 08:19:09 -06:00
_pendingSeek = false ;
2015-04-08 16:15:57 -06:00
}
2018-07-09 12:20:32 -06:00
2015-04-08 16:15:57 -06:00
} else {
_pendingSeek = true ;
2018-07-09 12:20:32 -06:00
_pendingSeekTime = [ seekTime floatValue ] ;
2015-04-08 16:15:57 -06:00
}
}
2015-05-30 13:50:45 -06:00
- ( void ) setRate : ( float ) rate
{
2015-04-07 21:38:16 -06:00
_rate = rate ;
[ self applyModifiers ] ;
}
2015-05-30 13:50:45 -06:00
- ( void ) setMuted : ( BOOL ) muted
{
2015-04-07 21:38:16 -06:00
_muted = muted ;
[ self applyModifiers ] ;
}
2015-05-30 13:50:45 -06:00
- ( void ) setVolume : ( float ) volume
{
2015-04-07 21:38:16 -06:00
_volume = volume ;
[ self applyModifiers ] ;
}
2018-11-26 15:50:31 -07:00
- ( void ) setMaxBitRate : ( float ) maxBitRate {
_maxBitRate = maxBitRate ;
2018-12-22 16:33:43 -07:00
_playerItem . preferredPeakBitRate = maxBitRate ;
2018-11-26 15:50:31 -07:00
}
2020-05-15 01:25:19 -06:00
- ( void ) setPreferredForwardBufferDuration : ( float ) preferredForwardBufferDuration
{
_preferredForwardBufferDuration = preferredForwardBufferDuration ;
_playerItem . preferredForwardBufferDuration = preferredForwardBufferDuration ;
}
2019-08-22 02:10:39 -06:00
- ( void ) setAutomaticallyWaitsToMinimizeStalling : ( BOOL ) waits
{
_automaticallyWaitsToMinimizeStalling = waits ;
_player . automaticallyWaitsToMinimizeStalling = waits ;
}
2018-11-26 15:50:31 -07:00
2015-05-30 13:50:45 -06:00
- ( void ) applyModifiers
{
2015-04-07 21:38:16 -06:00
if ( _muted ) {
2019-07-06 05:58:18 -06:00
if ( ! _controls ) {
[ _player setVolume : 0 ] ;
}
2015-07-18 06:38:56 -06:00
[ _player setMuted : YES ] ;
2015-04-07 21:38:16 -06:00
} else {
2015-07-18 06:38:56 -06:00
[ _player setVolume : _volume ] ;
[ _player setMuted : NO ] ;
2015-04-07 21:38:16 -06:00
}
2020-06-16 06:31:23 -06:00
if ( @ available ( iOS 12.0 , * ) ) {
self -> _player . preventsDisplaySleepDuringVideoPlayback = _preventsDisplaySleepDuringVideoPlayback ;
} else {
// Fallback on earlier versions
}
2018-08-09 10:58:03 -06:00
2018-12-22 16:33:43 -07:00
[ self setMaxBitRate : _maxBitRate ] ;
2018-07-17 15:14:21 -06:00
[ self setSelectedAudioTrack : _selectedAudioTrack ] ;
2018-06-02 03:24:13 -06:00
[ self setSelectedTextTrack : _selectedTextTrack ] ;
2015-06-16 02:07:50 -06:00
[ self setResizeMode : _resizeMode ] ;
[ self setRepeat : _repeat ] ;
2015-05-10 17:01:25 -06:00
[ self setPaused : _paused ] ;
2015-12-22 16:39:04 -07:00
[ self setControls : _controls ] ;
2018-06-05 19:40:12 -06:00
[ self setAllowsExternalPlayback : _allowsExternalPlayback ] ;
2015-04-07 21:38:16 -06:00
}
2015-04-04 18:55:37 -06:00
2015-04-08 00:49:14 -06:00
- ( void ) setRepeat : ( BOOL ) repeat {
2015-06-16 02:07:50 -06:00
_repeat = repeat ;
2015-03-31 00:29:15 -06:00
}
2018-07-17 15:14:21 -06:00
- ( void ) setMediaSelectionTrackForCharacteristic : ( AVMediaCharacteristic ) characteristic
withCriteria : ( NSDictionary * ) criteria
{
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSString * type = criteria [ @ "type" ] ;
AVMediaSelectionGroup * group = [ _player . currentItem . asset
mediaSelectionGroupForMediaCharacteristic : characteristic ] ;
AVMediaSelectionOption * mediaOption ;
2018-08-09 10:58:03 -06:00
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
if ( [ type isEqualToString : @ "disabled" ] ) {
// Do nothing . We want to ensure option is nil
} else if ( [ type isEqualToString : @ "language" ] || [ type isEqualToString : @ "title" ] ) {
NSString * value = criteria [ @ "value" ] ;
for ( int i = 0 ; i < group . options . count ; + + i ) {
AVMediaSelectionOption * currentOption = [ group . options objectAtIndex : i ] ;
NSString * optionValue ;
if ( [ type isEqualToString : @ "language" ] ) {
optionValue = [ currentOption extendedLanguageTag ] ;
} else {
optionValue = [ [ [ currentOption commonMetadata ]
valueForKey : @ "value" ]
objectAtIndex : 0 ] ;
}
if ( [ value isEqualToString : optionValue ] ) {
mediaOption = currentOption ;
break ;
}
}
// } else if ( [ type isEqualToString : @ "default" ] ) {
// option = group . defaultOption ; * /
} else if ( [ type isEqualToString : @ "index" ] ) {
if ( [ criteria [ @ "value" ] isKindOfClass : [ NSNumber class ] ] ) {
int index = [ criteria [ @ "value" ] intValue ] ;
if ( group . options . count > index ) {
mediaOption = [ group . options objectAtIndex : index ] ;
2018-08-09 10:58:03 -06:00
}
2018-07-17 15:14:21 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
} else { // default . invalid type or "system"
[ _player . currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup : group ] ;
return ;
}
2018-08-09 10:58:03 -06:00
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
// If a match isn ' t found , option will be nil and text tracks will be disabled
[ _player . currentItem selectMediaOption : mediaOption inMediaSelectionGroup : group ] ;
2018-07-17 15:14:21 -06:00
}
- ( void ) setSelectedAudioTrack : ( NSDictionary * ) selectedAudioTrack {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
_selectedAudioTrack = selectedAudioTrack ;
[ self setMediaSelectionTrackForCharacteristic : AVMediaCharacteristicAudible
withCriteria : _selectedAudioTrack ] ;
2018-07-17 15:14:21 -06:00
}
2018-07-06 17:38:24 -06:00
- ( void ) setSelectedTextTrack : ( NSDictionary * ) selectedTextTrack {
2018-07-09 17:28:38 -06:00
_selectedTextTrack = selectedTextTrack ;
2018-07-17 15:14:21 -06:00
if ( _textTracks ) { // sideloaded text tracks
2018-07-09 17:28:38 -06:00
[ self setSideloadedText ] ;
2018-07-17 15:14:21 -06:00
} else { // text tracks included in the HLS playlist
[ self setMediaSelectionTrackForCharacteristic : AVMediaCharacteristicLegible
withCriteria : _selectedTextTrack ] ;
2018-07-09 17:28:38 -06:00
}
2018-06-21 10:08:37 -06:00
}
2018-07-09 12:20:32 -06:00
- ( void ) setSideloadedText {
2018-06-21 10:08:37 -06:00
NSString * type = _selectedTextTrack [ @ "type" ] ;
2018-07-29 18:42:09 -06:00
NSArray * textTracks = [ self getTextTrackInfo ] ;
2018-06-21 10:08:37 -06:00
2018-07-09 17:28:38 -06:00
// The first few tracks will be audio & video track
int firstTextIndex = 0 ;
for ( firstTextIndex = 0 ; firstTextIndex < _player . currentItem . tracks . count ; + + firstTextIndex ) {
if ( [ _player . currentItem . tracks [ firstTextIndex ] . assetTrack hasMediaCharacteristic : AVMediaCharacteristicLegible ] ) {
break ;
}
}
2018-07-29 18:42:09 -06:00
int selectedTrackIndex = RCTVideoUnset ;
2018-06-21 10:08:37 -06:00
if ( [ type isEqualToString : @ "disabled" ] ) {
// Do nothing . We want to ensure option is nil
} else if ( [ type isEqualToString : @ "language" ] ) {
NSString * selectedValue = _selectedTextTrack [ @ "value" ] ;
for ( int i = 0 ; i < textTracks . count ; + + i ) {
2018-07-09 12:20:32 -06:00
NSDictionary * currentTextTrack = [ textTracks objectAtIndex : i ] ;
if ( [ selectedValue isEqualToString : currentTextTrack [ @ "language" ] ] ) {
2018-07-09 17:28:38 -06:00
selectedTrackIndex = i ;
2018-06-21 10:08:37 -06:00
break ;
}
}
} else if ( [ type isEqualToString : @ "title" ] ) {
NSString * selectedValue = _selectedTextTrack [ @ "value" ] ;
for ( int i = 0 ; i < textTracks . count ; + + i ) {
2018-07-09 12:20:32 -06:00
NSDictionary * currentTextTrack = [ textTracks objectAtIndex : i ] ;
if ( [ selectedValue isEqualToString : currentTextTrack [ @ "title" ] ] ) {
2018-07-09 17:28:38 -06:00
selectedTrackIndex = i ;
2018-06-21 10:08:37 -06:00
break ;
}
}
} else if ( [ type isEqualToString : @ "index" ] ) {
if ( [ _selectedTextTrack [ @ "value" ] isKindOfClass : [ NSNumber class ] ] ) {
int index = [ _selectedTextTrack [ @ "value" ] intValue ] ;
if ( textTracks . count > index ) {
2018-07-09 17:28:38 -06:00
selectedTrackIndex = index ;
2018-06-21 10:08:37 -06:00
}
}
2018-07-31 17:56:19 -06:00
}
// in the situation that a selected text track is not available ( eg . specifies a textTrack not available )
if ( ! [ type isEqualToString : @ "disabled" ] && selectedTrackIndex = = RCTVideoUnset ) {
2018-07-29 18:42:09 -06:00
CFArrayRef captioningMediaCharacteristics = MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics ( kMACaptionAppearanceDomainUser ) ;
NSArray * captionSettings = ( __bridge NSArray * ) captioningMediaCharacteristics ;
if ( [ captionSettings containsObject : AVMediaCharacteristicTranscribesSpokenDialogForAccessibility ] ) {
selectedTrackIndex = 0 ; // If we can ' t find a match , use the first available track
NSString * systemLanguage = [ [ NSLocale preferredLanguages ] firstObject ] ;
for ( int i = 0 ; i < textTracks . count ; + + i ) {
NSDictionary * currentTextTrack = [ textTracks objectAtIndex : i ] ;
if ( [ systemLanguage isEqualToString : currentTextTrack [ @ "language" ] ] ) {
selectedTrackIndex = i ;
break ;
2018-07-09 12:20:32 -06:00
}
2018-06-21 10:08:37 -06:00
}
2018-07-29 18:42:09 -06:00
}
2018-06-21 10:08:37 -06:00
}
2018-08-09 10:58:03 -06:00
2018-07-09 17:28:38 -06:00
for ( int i = firstTextIndex ; i < _player . currentItem . tracks . count ; + + i ) {
2018-07-29 18:42:09 -06:00
BOOL isEnabled = NO ;
if ( selectedTrackIndex ! = RCTVideoUnset ) {
isEnabled = i = = selectedTrackIndex + firstTextIndex ;
}
2018-07-09 17:28:38 -06:00
[ _player . currentItem . tracks [ i ] setEnabled : isEnabled ] ;
}
2018-06-21 10:08:37 -06:00
}
2018-07-09 12:20:32 -06:00
- ( void ) setStreamingText {
2018-06-21 10:08:37 -06:00
NSString * type = _selectedTextTrack [ @ "type" ] ;
2018-06-02 03:24:13 -06:00
AVMediaSelectionGroup * group = [ _player . currentItem . asset
mediaSelectionGroupForMediaCharacteristic : AVMediaCharacteristicLegible ] ;
2018-07-09 12:20:32 -06:00
AVMediaSelectionOption * mediaOption ;
2018-06-21 10:08:37 -06:00
2018-06-02 03:24:13 -06:00
if ( [ type isEqualToString : @ "disabled" ] ) {
// Do nothing . We want to ensure option is nil
} else if ( [ type isEqualToString : @ "language" ] || [ type isEqualToString : @ "title" ] ) {
2018-06-21 10:08:37 -06:00
NSString * value = _selectedTextTrack [ @ "value" ] ;
2018-06-02 03:24:13 -06:00
for ( int i = 0 ; i < group . options . count ; + + i ) {
AVMediaSelectionOption * currentOption = [ group . options objectAtIndex : i ] ;
NSString * optionValue ;
if ( [ type isEqualToString : @ "language" ] ) {
optionValue = [ currentOption extendedLanguageTag ] ;
} else {
optionValue = [ [ [ currentOption commonMetadata ]
valueForKey : @ "value" ]
objectAtIndex : 0 ] ;
}
if ( [ value isEqualToString : optionValue ] ) {
2018-07-09 12:20:32 -06:00
mediaOption = currentOption ;
2018-06-02 03:24:13 -06:00
break ;
}
}
2018-06-21 10:08:37 -06:00
// } else if ( [ type isEqualToString : @ "default" ] ) {
// option = group . defaultOption ; * /
2018-06-02 03:24:13 -06:00
} else if ( [ type isEqualToString : @ "index" ] ) {
2018-06-21 10:08:37 -06:00
if ( [ _selectedTextTrack [ @ "value" ] isKindOfClass : [ NSNumber class ] ] ) {
int index = [ _selectedTextTrack [ @ "value" ] intValue ] ;
2018-06-02 03:24:13 -06:00
if ( group . options . count > index ) {
2018-07-09 12:20:32 -06:00
mediaOption = [ group . options objectAtIndex : index ] ;
2018-06-02 03:24:13 -06:00
}
}
} else { // default . invalid type or "system"
2018-06-02 20:41:25 -06:00
[ _player . currentItem selectMediaOptionAutomaticallyInMediaSelectionGroup : group ] ;
2018-06-02 03:24:13 -06:00
return ;
}
// If a match isn ' t found , option will be nil and text tracks will be disabled
2018-07-09 12:20:32 -06:00
[ _player . currentItem selectMediaOption : mediaOption inMediaSelectionGroup : group ] ;
2018-06-02 03:24:13 -06:00
}
2018-06-21 10:08:37 -06:00
- ( void ) setTextTracks : ( NSArray * ) textTracks ;
{
_textTracks = textTracks ;
2018-08-09 10:58:03 -06:00
2018-07-09 12:20:32 -06:00
// in case textTracks was set after selectedTextTrack
if ( _selectedTextTrack ) [ self setSelectedTextTrack : _selectedTextTrack ] ;
2018-06-21 10:08:37 -06:00
}
2018-07-17 15:14:21 -06:00
- ( NSArray * ) getAudioTrackInfo
{
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSMutableArray * audioTracks = [ [ NSMutableArray alloc ] init ] ;
AVMediaSelectionGroup * group = [ _player . currentItem . asset
mediaSelectionGroupForMediaCharacteristic : AVMediaCharacteristicAudible ] ;
for ( int i = 0 ; i < group . options . count ; + + i ) {
AVMediaSelectionOption * currentOption = [ group . options objectAtIndex : i ] ;
NSString * title = @ "" ;
NSArray * values = [ [ currentOption commonMetadata ] valueForKey : @ "value" ] ;
if ( values . count > 0 ) {
title = [ values objectAtIndex : 0 ] ;
2018-07-17 15:14:21 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSString * language = [ currentOption extendedLanguageTag ] ? [ currentOption extendedLanguageTag ] : @ "" ;
NSDictionary * audioTrack = @ {
@ "index" : [ NSNumber numberWithInt : i ] ,
@ "title" : title ,
@ "language" : language
} ;
[ audioTracks addObject : audioTrack ] ;
}
return audioTracks ;
2018-07-17 15:14:21 -06:00
}
2018-06-11 21:55:23 -06:00
- ( NSArray * ) getTextTrackInfo
{
2018-06-21 10:08:37 -06:00
// if sideloaded , textTracks will already be set
if ( _textTracks ) return _textTracks ;
// if streaming video , we extract the text tracks
2018-06-11 21:55:23 -06:00
NSMutableArray * textTracks = [ [ NSMutableArray alloc ] init ] ;
AVMediaSelectionGroup * group = [ _player . currentItem . asset
mediaSelectionGroupForMediaCharacteristic : AVMediaCharacteristicLegible ] ;
for ( int i = 0 ; i < group . options . count ; + + i ) {
AVMediaSelectionOption * currentOption = [ group . options objectAtIndex : i ] ;
2018-07-09 12:20:32 -06:00
NSString * title = @ "" ;
NSArray * values = [ [ currentOption commonMetadata ] valueForKey : @ "value" ] ;
if ( values . count > 0 ) {
title = [ values objectAtIndex : 0 ] ;
}
NSString * language = [ currentOption extendedLanguageTag ] ? [ currentOption extendedLanguageTag ] : @ "" ;
2018-06-11 21:55:23 -06:00
NSDictionary * textTrack = @ {
@ "index" : [ NSNumber numberWithInt : i ] ,
@ "title" : title ,
2018-07-09 12:20:32 -06:00
@ "language" : language
2018-06-11 21:55:23 -06:00
} ;
[ textTracks addObject : textTrack ] ;
}
return textTracks ;
}
2016-03-31 12:34:22 -06:00
- ( BOOL ) getFullscreen
{
2018-02-28 09:42:49 -07:00
return _fullscreenPlayerPresented ;
2016-03-31 12:34:22 -06:00
}
2018-08-09 10:58:03 -06:00
- ( void ) setFullscreen : ( BOOL ) fullscreen {
2018-10-09 17:01:41 -06:00
if ( fullscreen && ! _fullscreenPlayerPresented && _player )
2018-08-09 10:58:03 -06:00
{
// Ensure player view controller is not null
if ( ! _playerViewController )
2016-03-31 12:34:22 -06:00
{
2018-02-28 09:42:49 -07:00
[ self usePlayerViewController ] ;
2016-03-31 12:34:22 -06:00
}
2018-02-28 09:42:49 -07:00
// Set presentation style to fullscreen
[ _playerViewController setModalPresentationStyle : UIModalPresentationFullScreen ] ;
// Find the nearest view controller
UIViewController * viewController = [ self firstAvailableUIViewController ] ;
if ( ! viewController )
2016-03-31 12:34:22 -06:00
{
2018-02-28 09:42:49 -07:00
UIWindow * keyWindow = [ [ UIApplication sharedApplication ] keyWindow ] ;
viewController = keyWindow . rootViewController ;
if ( viewController . childViewControllers . count > 0 )
{
viewController = viewController . childViewControllers . lastObject ;
}
2016-03-31 12:34:22 -06:00
}
2018-02-28 09:42:49 -07:00
if ( viewController )
2016-03-31 12:34:22 -06:00
{
2018-02-28 09:42:49 -07:00
_presentingViewController = viewController ;
if ( self . onVideoFullscreenPlayerWillPresent ) {
self . onVideoFullscreenPlayerWillPresent ( @ { @ "target" : self . reactTag } ) ;
}
[ viewController presentViewController : _playerViewController animated : true completion : ^ {
_playerViewController . showsPlaybackControls = YES ;
2018-10-07 21:24:50 -06:00
_fullscreenPlayerPresented = fullscreen ;
2018-10-18 16:21:46 -06:00
_playerViewController . autorotate = _fullscreenAutorotate ;
2018-02-28 09:42:49 -07:00
if ( self . onVideoFullscreenPlayerDidPresent ) {
self . onVideoFullscreenPlayerDidPresent ( @ { @ "target" : self . reactTag } ) ;
}
} ] ;
2016-03-31 12:34:22 -06:00
}
2018-02-28 09:42:49 -07:00
}
2018-10-07 21:24:50 -06:00
else if ( ! fullscreen && _fullscreenPlayerPresented )
2018-02-28 09:42:49 -07:00
{
[ self videoPlayerViewControllerWillDismiss : _playerViewController ] ;
[ _presentingViewController dismissViewControllerAnimated : true completion : ^ {
[ self videoPlayerViewControllerDidDismiss : _playerViewController ] ;
} ] ;
}
2016-03-31 12:34:22 -06:00
}
2018-10-18 16:21:46 -06:00
- ( void ) setFullscreenAutorotate : ( BOOL ) autorotate {
_fullscreenAutorotate = autorotate ;
if ( _fullscreenPlayerPresented ) {
_playerViewController . autorotate = autorotate ;
}
}
2018-10-07 21:24:50 -06:00
- ( void ) setFullscreenOrientation : ( NSString * ) orientation {
_fullscreenOrientation = orientation ;
if ( _fullscreenPlayerPresented ) {
_playerViewController . preferredOrientation = orientation ;
}
2016-03-31 12:34:22 -06:00
}
2015-12-22 16:39:04 -07:00
- ( void ) usePlayerViewController
{
2018-02-28 09:42:49 -07:00
if ( _player )
{
2019-06-19 07:18:25 -06:00
if ( ! _playerViewController ) {
_playerViewController = [ self createPlayerViewController : _player withPlayerItem : _playerItem ] ;
}
2018-02-28 09:42:49 -07:00
// to prevent video from being animated when resizeMode is ' cover '
// resize mode must be set before subview is added
[ self setResizeMode : _resizeMode ] ;
2019-01-21 15:05:03 -07:00
if ( _controls ) {
UIViewController * viewController = [ self reactViewController ] ;
[ viewController addChildViewController : _playerViewController ] ;
[ self addSubview : _playerViewController . view ] ;
}
2019-06-19 07:18:25 -06:00
[ _playerViewController addObserver : self forKeyPath : readyForDisplayKeyPath options : NSKeyValueObservingOptionNew context : nil ] ;
2019-01-21 15:05:03 -07:00
[ _playerViewController . contentOverlayView addObserver : self forKeyPath : @ "frame" options : NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context : NULL ] ;
2018-02-28 09:42:49 -07:00
}
2015-12-22 16:39:04 -07:00
}
- ( void ) usePlayerLayer
{
2018-07-09 12:20:32 -06:00
if ( _player )
{
_playerLayer = [ AVPlayerLayer playerLayerWithPlayer : _player ] ;
_playerLayer . frame = self . bounds ;
_playerLayer . needsDisplayOnBoundsChange = YES ;
// to prevent video from being animated when resizeMode is ' cover '
// resize mode must be set before layer is added
[ self setResizeMode : _resizeMode ] ;
[ _playerLayer addObserver : self forKeyPath : readyForDisplayKeyPath options : NSKeyValueObservingOptionNew context : nil ] ;
_playerLayerObserverSet = YES ;
[ self . layer addSublayer : _playerLayer ] ;
self . layer . needsDisplayOnBoundsChange = YES ;
2019-03-11 20:55:36 -06:00
# if TARGET_OS _IOS
2018-10-26 14:33:03 -06:00
[ self setupPipController ] ;
2019-03-11 20:55:36 -06:00
# endif
2018-07-09 12:20:32 -06:00
}
2015-12-22 16:39:04 -07:00
}
- ( void ) setControls : ( BOOL ) controls
{
2018-02-28 09:42:49 -07:00
if ( _controls ! = controls || ( ! _playerLayer && ! _playerViewController ) )
{
_controls = controls ;
if ( _controls )
2015-12-22 16:39:04 -07:00
{
2018-02-28 09:42:49 -07:00
[ self removePlayerLayer ] ;
[ self usePlayerViewController ] ;
}
else
{
[ _playerViewController . view removeFromSuperview ] ;
_playerViewController = nil ;
[ self usePlayerLayer ] ;
2015-12-22 16:39:04 -07:00
}
2018-02-28 09:42:49 -07:00
}
2015-12-22 16:39:04 -07:00
}
2016-10-01 12:23:50 -06:00
- ( void ) setProgressUpdateInterval : ( float ) progressUpdateInterval
{
_progressUpdateInterval = progressUpdateInterval ;
2018-08-09 10:58:03 -06:00
2017-09-28 19:37:52 -06:00
if ( _timeObserver ) {
[ self removePlayerTimeObserver ] ;
[ self addPlayerTimeObserver ] ;
}
2016-10-01 12:23:50 -06:00
}
2016-04-28 06:25:45 -06:00
- ( void ) removePlayerLayer
{
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
if ( _loadingRequest ! = nil ) {
[ _loadingRequest finishLoading ] ;
}
_requestingCertificate = NO ;
_requestingCertificateErrored = NO ;
2018-07-09 12:20:32 -06:00
[ _playerLayer removeFromSuperlayer ] ;
if ( _playerLayerObserverSet ) {
2018-06-21 10:08:37 -06:00
[ _playerLayer removeObserver : self forKeyPath : readyForDisplayKeyPath ] ;
2018-07-09 12:20:32 -06:00
_playerLayerObserverSet = NO ;
}
_playerLayer = nil ;
2016-04-28 06:25:45 -06:00
}
2016-04-01 02:52:05 -06:00
# pragma mark - RCTVideoPlayerViewControllerDelegate
- ( void ) videoPlayerViewControllerWillDismiss : ( AVPlayerViewController * ) playerViewController
{
2018-02-28 09:42:49 -07:00
if ( _playerViewController = = playerViewController && _fullscreenPlayerPresented && self . onVideoFullscreenPlayerWillDismiss )
{
2019-11-19 13:47:15 -07:00
@ try {
[ _playerViewController . contentOverlayView removeObserver : self forKeyPath : @ "frame" ] ;
[ _playerViewController removeObserver : self forKeyPath : readyForDisplayKeyPath ] ;
} @ catch ( id anException ) {
}
2018-02-28 09:42:49 -07:00
self . onVideoFullscreenPlayerWillDismiss ( @ { @ "target" : self . reactTag } ) ;
}
2016-04-01 02:52:05 -06:00
}
- ( void ) videoPlayerViewControllerDidDismiss : ( AVPlayerViewController * ) playerViewController
{
2018-02-28 09:42:49 -07:00
if ( _playerViewController = = playerViewController && _fullscreenPlayerPresented )
{
_fullscreenPlayerPresented = false ;
_presentingViewController = nil ;
_playerViewController = nil ;
[ self applyModifiers ] ;
if ( self . onVideoFullscreenPlayerDidDismiss ) {
self . onVideoFullscreenPlayerDidDismiss ( @ { @ "target" : self . reactTag } ) ;
2016-04-01 02:52:05 -06:00
}
2018-02-28 09:42:49 -07:00
}
2016-04-01 02:52:05 -06:00
}
2018-11-06 07:38:28 -07:00
- ( void ) setFilter : ( NSString * ) filterName {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
_filterName = filterName ;
if ( ! _filterEnabled ) {
return ;
} else if ( [ [ _source objectForKey : @ "uri" ] rangeOfString : @ "m3u8" ] . location ! = NSNotFound ) {
return ; // filters don ' t work for HLS . . . return
} else if ( ! _playerItem . asset ) {
return ;
}
CIFilter * filter = [ CIFilter filterWithName : filterName ] ;
_playerItem . videoComposition = [ AVVideoComposition
videoCompositionWithAsset : _playerItem . asset
applyingCIFiltersWithHandler : ^ ( AVAsynchronousCIImageFilteringRequest * _Nonnull request ) {
if ( filter = = nil ) {
[ request finishWithImage : request . sourceImage context : nil ] ;
} else {
CIImage * image = request . sourceImage . imageByClampingToExtent ;
[ filter setValue : image forKey : kCIInputImageKey ] ;
CIImage * output = [ filter . outputImage imageByCroppingToRect : request . sourceImage . extent ] ;
[ request finishWithImage : output context : nil ] ;
}
} ] ;
2018-10-27 19:43:14 -06:00
}
2018-12-13 20:30:38 -07:00
- ( void ) setFilterEnabled : ( BOOL ) filterEnabled {
_filterEnabled = filterEnabled ;
}
2015-04-08 11:34:27 -06:00
# pragma mark - React View Management
2015-04-08 09:46:13 -06:00
2015-05-30 13:50:45 -06:00
- ( void ) insertReactSubview : ( UIView * ) view atIndex : ( NSInteger ) atIndex
{
2015-12-22 16:39:04 -07:00
// We are early in the game and somebody wants to set a subview .
// That can only be in the context of playerViewController .
if ( ! _controls && ! _playerLayer && ! _playerViewController )
{
[ self setControls : true ] ;
}
2018-02-28 09:42:49 -07:00
2015-12-22 16:39:04 -07:00
if ( _controls )
{
2018-02-28 09:42:49 -07:00
view . frame = self . bounds ;
[ _playerViewController . contentOverlayView insertSubview : view atIndex : atIndex ] ;
2015-12-22 16:39:04 -07:00
}
else
{
2018-02-28 09:42:49 -07:00
RCTLogError ( @ "video cannot have any subviews" ) ;
2015-12-22 16:39:04 -07:00
}
2015-03-30 23:07:55 -06:00
return ;
}
2015-05-30 13:50:45 -06:00
- ( void ) removeReactSubview : ( UIView * ) subview
{
2015-12-22 16:39:04 -07:00
if ( _controls )
{
2018-02-28 09:42:49 -07:00
[ subview removeFromSuperview ] ;
2015-12-22 16:39:04 -07:00
}
else
{
RCTLogError ( @ "video cannot have any subviews" ) ;
}
2015-03-30 23:07:55 -06:00
return ;
}
2015-05-30 13:50:45 -06:00
- ( void ) layoutSubviews
{
2015-03-30 23:07:55 -06:00
[ super layoutSubviews ] ;
2015-12-22 16:39:04 -07:00
if ( _controls )
{
_playerViewController . view . frame = self . bounds ;
2018-02-28 09:42:49 -07:00
2015-12-22 16:39:04 -07:00
// also adjust all subviews of contentOverlayView
for ( UIView * subview in _playerViewController . contentOverlayView . subviews ) {
subview . frame = self . bounds ;
}
}
else
{
2018-02-28 09:42:49 -07:00
[ CATransaction begin ] ;
[ CATransaction setAnimationDuration : 0 ] ;
_playerLayer . frame = self . bounds ;
[ CATransaction commit ] ;
2015-12-22 16:39:04 -07:00
}
2015-04-04 18:55:37 -06:00
}
2015-04-08 11:34:27 -06:00
# pragma mark - Lifecycle
2015-04-08 09:46:13 -06:00
2015-05-30 13:50:45 -06:00
- ( void ) removeFromSuperview
{
2015-04-10 01:15:19 -06:00
[ _player pause ] ;
2016-05-17 01:40:58 -06:00
if ( _playbackRateObserverRegistered ) {
2016-05-19 12:27:23 -06:00
[ _player removeObserver : self forKeyPath : playbackRate context : nil ] ;
2016-05-17 01:38:35 -06:00
_playbackRateObserverRegistered = NO ;
2016-05-17 01:40:58 -06:00
}
2018-09-13 06:06:12 -06:00
if ( _isExternalPlaybackActiveObserverRegistered ) {
[ _player removeObserver : self forKeyPath : externalPlaybackActive context : nil ] ;
_isExternalPlaybackActiveObserverRegistered = NO ;
}
2015-04-10 01:15:19 -06:00
_player = nil ;
2018-02-28 09:42:49 -07:00
2016-04-28 06:25:45 -06:00
[ self removePlayerLayer ] ;
2018-02-28 09:42:49 -07:00
2019-01-21 15:05:03 -07:00
[ _playerViewController . contentOverlayView removeObserver : self forKeyPath : @ "frame" ] ;
2019-06-19 07:18:25 -06:00
[ _playerViewController removeObserver : self forKeyPath : readyForDisplayKeyPath ] ;
2015-12-22 16:39:04 -07:00
[ _playerViewController . view removeFromSuperview ] ;
2019-07-03 00:44:55 -06:00
_playerViewController . rctDelegate = nil ;
_playerViewController . player = nil ;
2015-12-22 16:39:04 -07:00
_playerViewController = nil ;
2018-02-28 09:42:49 -07:00
2015-12-22 16:39:04 -07:00
[ self removePlayerTimeObserver ] ;
2015-08-05 06:52:30 -06:00
[ self removePlayerItemObservers ] ;
2018-02-28 09:42:49 -07:00
2015-04-10 01:15:19 -06:00
_eventDispatcher = nil ;
2015-04-04 18:55:37 -06:00
[ [ NSNotificationCenter defaultCenter ] removeObserver : self ] ;
2018-02-28 09:42:49 -07:00
2015-06-24 22:26:36 -06:00
[ super removeFromSuperview ] ;
2015-03-30 23:07:55 -06:00
}
2018-10-27 19:43:14 -06:00
# pragma mark - Export
2018-10-26 07:21:41 -06:00
- ( void ) save : ( NSDictionary * ) options resolve : ( RCTPromiseResolveBlock ) resolve reject : ( RCTPromiseRejectBlock ) reject {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
AVAsset * asset = _playerItem . asset ;
if ( asset ! = nil ) {
AVAssetExportSession * exportSession = [ AVAssetExportSession
exportSessionWithAsset : asset presetName : AVAssetExportPresetHighestQuality ] ;
if ( exportSession ! = nil ) {
NSString * path = nil ;
NSArray * array = NSSearchPathForDirectoriesInDomains ( NSCachesDirectory , NSUserDomainMask , YES ) ;
path = [ self generatePathInDirectory : [ [ self cacheDirectoryPath ] stringByAppendingPathComponent : @ "Videos" ]
withExtension : @ ".mp4" ] ;
NSURL * url = [ NSURL fileURLWithPath : path ] ;
exportSession . outputFileType = AVFileTypeMPEG4 ;
exportSession . outputURL = url ;
exportSession . videoComposition = _playerItem . videoComposition ;
exportSession . shouldOptimizeForNetworkUse = true ;
[ exportSession exportAsynchronouslyWithCompletionHandler : ^ {
switch ( [ exportSession status ] ) {
case AVAssetExportSessionStatusFailed :
reject ( @ "ERROR_COULD_NOT_EXPORT_VIDEO" , @ "Could not export video" , exportSession . error ) ;
break ;
case AVAssetExportSessionStatusCancelled :
reject ( @ "ERROR_EXPORT_SESSION_CANCELLED" , @ "Export session was cancelled" , exportSession . error ) ;
break ;
default :
resolve ( @ { @ "uri" : url . absoluteString } ) ;
break ;
2018-10-26 07:21:41 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
} ] ;
2018-10-26 07:21:41 -06:00
} else {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
reject ( @ "ERROR_COULD_NOT_CREATE_EXPORT_SESSION" , @ "Could not create export session" , nil ) ;
}
} else {
reject ( @ "ERROR_ASSET_NIL" , @ "Asset is nil" , nil ) ;
}
}
2018-10-25 07:56:20 -06:00
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
- ( void ) setLicenseResult : ( NSString * ) license {
NSData * respondData = [ self base64DataFromBase64String : license ] ;
if ( _loadingRequest ! = nil && respondData ! = nil ) {
AVAssetResourceLoadingDataRequest * dataRequest = [ _loadingRequest dataRequest ] ;
[ dataRequest respondWithData : respondData ] ;
[ _loadingRequest finishLoading ] ;
} else {
[ self setLicenseResultError : @ "No data from JS license response" ] ;
}
}
- ( BOOL ) setLicenseResultError : ( NSString * ) error {
if ( _loadingRequest ! = nil ) {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorFromJSPart
userInfo : @ {
NSLocalizedDescriptionKey : error ,
NSLocalizedFailureReasonErrorKey : error ,
NSLocalizedRecoverySuggestionErrorKey : error
}
] ;
[ self finishLoadingWithError : licenseError ] ;
}
return NO ;
}
- ( BOOL ) finishLoadingWithError : ( NSError * ) error {
if ( _loadingRequest && error ! = nil ) {
NSError * licenseError = error ;
[ _loadingRequest finishLoadingWithError : licenseError ] ;
if ( self . onVideoError ) {
self . onVideoError ( @ { @ "error" : @ { @ "code" : [ NSNumber numberWithInteger : error . code ] ,
@ "localizedDescription" : [ error localizedDescription ] = = nil ? @ "" : [ error localizedDescription ] ,
@ "localizedFailureReason" : [ error localizedFailureReason ] = = nil ? @ "" : [ error localizedFailureReason ] ,
@ "localizedRecoverySuggestion" : [ error localizedRecoverySuggestion ] = = nil ? @ "" : [ error localizedRecoverySuggestion ] ,
@ "domain" : _playerItem . error = = nil ? @ "RCTVideo" : _playerItem . error . domain } ,
@ "target" : self . reactTag } ) ;
2018-10-26 07:21:41 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
}
return NO ;
2018-10-26 07:21:41 -06:00
}
- ( BOOL ) ensureDirExistsWithPath : ( NSString * ) path {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
BOOL isDir = NO ;
NSError * error ;
BOOL exists = [ [ NSFileManager defaultManager ] fileExistsAtPath : path isDirectory : & isDir ] ;
if ( ! ( exists && isDir ) ) {
[ [ NSFileManager defaultManager ] createDirectoryAtPath : path withIntermediateDirectories : YES attributes : nil error : & error ] ;
if ( error ) {
return NO ;
2018-10-26 07:21:41 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
}
return YES ;
2018-10-26 07:21:41 -06:00
}
- ( NSString * ) generatePathInDirectory : ( NSString * ) directory withExtension : ( NSString * ) extension {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSString * fileName = [ [ [ NSUUID UUID ] UUIDString ] stringByAppendingString : extension ] ;
[ self ensureDirExistsWithPath : directory ] ;
return [ directory stringByAppendingPathComponent : fileName ] ;
2018-10-26 07:21:41 -06:00
}
2018-10-25 07:56:20 -06:00
2018-10-26 07:21:41 -06:00
- ( NSString * ) cacheDirectoryPath {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSArray * array = NSSearchPathForDirectoriesInDomains ( NSCachesDirectory , NSUserDomainMask , YES ) ;
return array [ 0 ] ;
2015-03-30 23:07:55 -06:00
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
# pragma mark - AVAssetResourceLoaderDelegate
- ( BOOL ) resourceLoader : ( AVAssetResourceLoader * ) resourceLoader shouldWaitForRenewalOfRequestedResource : ( AVAssetResourceRenewalRequest * ) renewalRequest {
return [ self loadingRequestHandling : renewalRequest ] ;
}
- ( BOOL ) resourceLoader : ( AVAssetResourceLoader * ) resourceLoader shouldWaitForLoadingOfRequestedResource : ( AVAssetResourceLoadingRequest * ) loadingRequest {
return [ self loadingRequestHandling : loadingRequest ] ;
}
- ( void ) resourceLoader : ( AVAssetResourceLoader * ) resourceLoader
didCancelLoadingRequest : ( AVAssetResourceLoadingRequest * ) loadingRequest {
NSLog ( @ "didCancelLoadingRequest" ) ;
}
- ( BOOL ) loadingRequestHandling : ( AVAssetResourceLoadingRequest * ) loadingRequest {
if ( self -> _requestingCertificate ) {
return YES ;
} else if ( self -> _requestingCertificateErrored ) {
return NO ;
}
_loadingRequest = loadingRequest ;
NSURL * url = loadingRequest . request . URL ;
if ( self -> _drm ! = nil ) {
2021-01-13 03:18:01 -07:00
NSString * contentId ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSString * contentIdOverride = ( NSString * ) [ self -> _drm objectForKey : @ "contentId" ] ;
if ( contentIdOverride ! = nil ) {
contentId = contentIdOverride ;
2021-01-13 03:18:01 -07:00
} else if ( self . onGetLicense ) {
contentId = url . host ;
} else {
contentId = [ url . absoluteString stringByReplacingOccurrencesOfString : @ "skd://" withString : @ "" ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
}
NSString * drmType = ( NSString * ) [ self -> _drm objectForKey : @ "type" ] ;
if ( [ drmType isEqualToString : @ "fairplay" ] ) {
NSString * certificateStringUrl = ( NSString * ) [ self -> _drm objectForKey : @ "certificateUrl" ] ;
if ( certificateStringUrl ! = nil ) {
NSURL * certificateURL = [ NSURL URLWithString : [ certificateStringUrl stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding ] ] ;
dispatch_async ( dispatch_get _global _queue ( DISPATCH_QUEUE _PRIORITY _DEFAULT , 0 ) , ^ {
NSData * certificateData = [ NSData dataWithContentsOfURL : certificateURL ] ;
if ( [ self -> _drm objectForKey : @ "base64Certificate" ] ) {
certificateData = [ [ NSData alloc ] initWithBase64EncodedData : certificateData options : NSDataBase64DecodingIgnoreUnknownCharacters ] ;
}
if ( certificateData ! = nil ) {
2021-01-13 03:18:01 -07:00
NSData * contentIdData ;
if ( self . onGetLicense ) {
contentIdData = [ contentId dataUsingEncoding : NSUTF8StringEncoding ] ;
} else {
contentIdData = [ NSData dataWithBytes : [ contentId cStringUsingEncoding : NSUTF8StringEncoding ] length : [ contentId lengthOfBytesUsingEncoding : NSUTF8StringEncoding ] ] ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
AVAssetResourceLoadingDataRequest * dataRequest = [ loadingRequest dataRequest ] ;
if ( dataRequest ! = nil ) {
NSError * spcError = nil ;
NSData * spcData = [ loadingRequest streamingContentKeyRequestDataForApp : certificateData contentIdentifier : contentIdData options : nil error : & spcError ] ;
// Request CKC to the server
NSString * licenseServer = ( NSString * ) [ self -> _drm objectForKey : @ "licenseServer" ] ;
if ( spcError ! = nil ) {
[ self finishLoadingWithError : spcError ] ;
self -> _requestingCertificateErrored = YES ;
}
if ( spcData ! = nil ) {
if ( self . onGetLicense ) {
2021-01-13 03:18:01 -07:00
NSString * base64Encoded = [ spcData base64EncodedStringWithOptions : 0 ] ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
self -> _requestingCertificate = YES ;
2021-01-13 03:18:01 -07:00
if ( licenseServer = = nil ) {
licenseServer = @ "" ;
}
self . onGetLicense ( @ { @ "licenseUrl" : licenseServer ,
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
@ "contentId" : contentId ,
2021-01-13 03:18:01 -07:00
@ "spcBase64" : base64Encoded ,
@ "target" : self . reactTag }
) ;
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
} else if ( licenseServer ! = nil ) {
NSMutableURLRequest * request = [ [ NSMutableURLRequest alloc ] init ] ;
[ request setHTTPMethod : @ "POST" ] ;
[ request setURL : [ NSURL URLWithString : licenseServer ] ] ;
// HEADERS
NSDictionary * headers = ( NSDictionary * ) [ self -> _drm objectForKey : @ "headers" ] ;
if ( headers ! = nil ) {
for ( NSString * key in headers ) {
NSString * value = headers [ key ] ;
[ request setValue : value forHTTPHeaderField : key ] ;
}
}
2021-01-13 03:18:01 -07:00
if ( self . onGetLicense ) {
[ request setHTTPBody : spcData ] ;
} else {
NSString * spcEncoded = [ spcData base64EncodedStringWithOptions : 0 ] ;
NSString * spcUrlEncoded = ( NSString * ) CFBridgingRelease ( CFURLCreateStringByAddingPercentEscapes ( kCFAllocatorDefault , ( CFStringRef ) spcEncoded , NULL , CFSTR ( "?=&+" ) , kCFStringEncodingUTF8 ) ) ;
NSString * post = [ NSString stringWithFormat : @ "spc=%@&%@" , spcUrlEncoded , contentId ] ;
NSData * postData = [ post dataUsingEncoding : NSUTF8StringEncoding allowLossyConversion : YES ] ;
[ request setHTTPBody : postData ] ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
NSURLSessionConfiguration * configuration = [ NSURLSessionConfiguration defaultSessionConfiguration ] ;
NSURLSession * session = [ NSURLSession sessionWithConfiguration : configuration delegate : self delegateQueue : nil ] ;
NSURLSessionDataTask * postDataTask = [ session dataTaskWithRequest : request completionHandler : ^ ( NSData * data , NSURLResponse * response , NSError * error ) {
NSHTTPURLResponse * httpResponse = ( NSHTTPURLResponse * ) response ;
if ( error ! = nil ) {
NSLog ( @ "Error getting license from %@, HTTP status code %li" , url , ( long ) [ httpResponse statusCode ] ) ;
[ self finishLoadingWithError : error ] ;
self -> _requestingCertificateErrored = YES ;
} else {
if ( [ httpResponse statusCode ] ! = 200 ) {
NSLog ( @ "Error getting license from %@, HTTP status code %li" , url , ( long ) [ httpResponse statusCode ] ) ;
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorLicenseRequestNotOk
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining license." ,
NSLocalizedFailureReasonErrorKey : [ NSString stringWithFormat : @ "License server responded with status code %li" , ( long ) [ httpResponse statusCode ] ] ,
NSLocalizedRecoverySuggestionErrorKey : @ "Did you send the correct data to the license Server? Is the server ok?"
}
] ;
[ self finishLoadingWithError : licenseError ] ;
self -> _requestingCertificateErrored = YES ;
} else if ( data ! = nil ) {
2021-01-13 03:18:01 -07:00
if ( self . onGetLicense ) {
[ dataRequest respondWithData : data ] ;
} else {
NSData * decodedData = [ [ NSData alloc ] initWithBase64EncodedData : data options : 0 ] ;
[ dataRequest respondWithData : decodedData ] ;
}
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
[ loadingRequest finishLoading ] ;
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoDataFromLicenseRequest
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining DRM license." ,
NSLocalizedFailureReasonErrorKey : @ "No data received from the license server." ,
NSLocalizedRecoverySuggestionErrorKey : @ "Is the licenseServer ok?."
}
] ;
[ self finishLoadingWithError : licenseError ] ;
self -> _requestingCertificateErrored = YES ;
}
2021-01-13 03:18:01 -07:00
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
}
} ] ;
[ postDataTask resume ] ;
}
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoSPC
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining license." ,
NSLocalizedFailureReasonErrorKey : @ "No spc received." ,
NSLocalizedRecoverySuggestionErrorKey : @ "Check your DRM config."
}
] ;
[ self finishLoadingWithError : licenseError ] ;
self -> _requestingCertificateErrored = YES ;
}
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoDataRequest
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining DRM license." ,
NSLocalizedFailureReasonErrorKey : @ "No dataRequest found." ,
NSLocalizedRecoverySuggestionErrorKey : @ "Check your DRM configuration."
}
] ;
[ self finishLoadingWithError : licenseError ] ;
self -> _requestingCertificateErrored = YES ;
}
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoCertificateData
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining DRM license." ,
NSLocalizedFailureReasonErrorKey : @ "No certificate data obtained from the specificied url." ,
NSLocalizedRecoverySuggestionErrorKey : @ "Have you specified a valid 'certificateUrl'?"
}
] ;
[ self finishLoadingWithError : licenseError ] ;
self -> _requestingCertificateErrored = YES ;
}
} ) ;
return YES ;
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoCertificateURL
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining DRM License." ,
NSLocalizedFailureReasonErrorKey : @ "No certificate URL has been found." ,
NSLocalizedRecoverySuggestionErrorKey : @ "Did you specified the prop certificateUrl?"
}
] ;
return [ self finishLoadingWithError : licenseError ] ;
}
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoFairplayDRM
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining DRM license." ,
NSLocalizedFailureReasonErrorKey : @ "Not a valid DRM Scheme has found" ,
NSLocalizedRecoverySuggestionErrorKey : @ "Have you specified the 'drm' 'type' as fairplay?"
}
] ;
return [ self finishLoadingWithError : licenseError ] ;
}
} else {
NSError * licenseError = [ NSError errorWithDomain : @ "RCTVideo"
code : RCTVideoErrorNoDRMData
userInfo : @ {
NSLocalizedDescriptionKey : @ "Error obtaining DRM license." ,
NSLocalizedFailureReasonErrorKey : @ "No drm object found." ,
NSLocalizedRecoverySuggestionErrorKey : @ "Have you specified the 'drm' prop?"
}
] ;
return [ self finishLoadingWithError : licenseError ] ;
}
return NO ;
}
- ( NSData * ) base64DataFromBase64String : ( NSString * ) base64String {
if ( base64String ! = nil ) {
// NSData from the Base64 encoded str
NSData * base64Data = [ [ NSData alloc ] initWithBase64EncodedString : base64String options : NSASCIIStringEncoding ] ;
return base64Data ;
}
return nil ;
}
2018-10-26 14:33:03 -06:00
# pragma mark - Picture in Picture
2019-03-11 20:55:36 -06:00
# if TARGET_OS _IOS
2018-10-26 14:33:03 -06:00
- ( void ) pictureInPictureControllerDidStopPictureInPicture : ( AVPictureInPictureController * ) pictureInPictureController {
2018-11-26 15:23:04 -07:00
if ( self . onPictureInPictureStatusChanged ) {
self . onPictureInPictureStatusChanged ( @ {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
@ "isActive" : [ NSNumber numberWithBool : false ]
} ) ;
2018-10-26 14:33:03 -06:00
}
}
- ( void ) pictureInPictureControllerDidStartPictureInPicture : ( AVPictureInPictureController * ) pictureInPictureController {
2018-11-26 15:23:04 -07:00
if ( self . onPictureInPictureStatusChanged ) {
self . onPictureInPictureStatusChanged ( @ {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
@ "isActive" : [ NSNumber numberWithBool : true ]
} ) ;
2018-10-26 14:33:03 -06:00
}
}
- ( void ) pictureInPictureControllerWillStopPictureInPicture : ( AVPictureInPictureController * ) pictureInPictureController {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-10-26 14:33:03 -06:00
}
- ( void ) pictureInPictureControllerWillStartPictureInPicture : ( AVPictureInPictureController * ) pictureInPictureController {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-10-26 14:33:03 -06:00
}
- ( void ) pictureInPictureController : ( AVPictureInPictureController * ) pictureInPictureController failedToStartPictureInPictureWithError : ( NSError * ) error {
Add iOS and Android basic DRM support (#1445)
This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey)
I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR.
**Test stream for ANDROID:**
```
testStream = {
uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)',
type: 'mpd',
drm: {
type: DRMType.PLAYREADY,
licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)'
}
};
```
or
```
{
uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd',
drm: {
type: 'widevine', //or DRMType.WIDEVINE
licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense',
headers: {
'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU'
},
}
}
```
**Test stream for iOS:**
Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them.
It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README)
2020-08-12 19:56:21 -06:00
2018-10-26 14:33:03 -06:00
}
- ( void ) pictureInPictureController : ( AVPictureInPictureController * ) pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler : ( void ( ^ ) ( BOOL ) ) completionHandler {
NSAssert ( _restoreUserInterfaceForPIPStopCompletionHandler = = NULL , @ "restoreUserInterfaceForPIPStopCompletionHandler was not called after picture in picture was exited." ) ;
2018-11-26 15:23:04 -07:00
if ( self . onRestoreUserInterfaceForPictureInPictureStop ) {
self . onRestoreUserInterfaceForPictureInPictureStop ( @ { } ) ;
}
2018-10-26 14:33:03 -06:00
_restoreUserInterfaceForPIPStopCompletionHandler = completionHandler ;
}
2019-03-11 20:55:36 -06:00
# endif
2018-10-26 14:33:03 -06:00
2015-03-30 23:07:55 -06:00
@ end