Skip to content

Commit

Permalink
Merge branch 'release/2.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
defagos committed Aug 28, 2017
2 parents 910c5c7 + 54d5c39 commit 514d427
Show file tree
Hide file tree
Showing 21 changed files with 810 additions and 156 deletions.
4 changes: 2 additions & 2 deletions Demo/Resources/MediaURLs.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<array>
<dict>
<key>name</key>
<string>Euronews</string>
<string>Livestream</string>
<key>url</key>
<string>http://fr-par-iphone-2.cdn.hexaglobe.net/streaming/euronews_ewns/9-live.m3u8</string>
<string>http://ndr_fs-lh.akamaihd.net/i/ndrfs_nds@119224/master.m3u8?dw=0</string>
</dict>
<dict>
<key>name</key>
Expand Down
9 changes: 4 additions & 5 deletions Demo/Resources/MultiplayerURLs.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
<array>
<dict>
<key>name</key>
<string>Live</string>
<string>Example</string>
<key>url</key>
<string>https://wowza.jwplayer.com/live/jelly.stream/playlist.m3u8?DVR</string>
<string>http://ndr_fs-lh.akamaihd.net/i/ndrfs_nds@119224/master.m3u8?dw=0</string>
<key>secondaryUrls</key>
<array>
<string>https://wowza.jwplayer.com/live/jelly.stream/playlist.m3u8?DVR</string>
<string>https://wowza.jwplayer.com/live/jelly.stream/playlist.m3u8?DVR</string>
<string>http://fr-par-iphone-2.cdn.hexaglobe.net/streaming/euronews_ewns/9-live.m3u8</string>
<string>https://devimages.apple.com.edgekey.net/streaming/examples/bipbop_4x3/bipbop_4x3_variant.m3u8</string>
<string>http://tagesschau-lh.akamaihd.net/i/tagesschau_1@119231/master.m3u8</string>
</array>
</dict>
</array>
Expand Down
4 changes: 2 additions & 2 deletions Demo/Resources/TimeshiftURLs.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<array>
<dict>
<key>name</key>
<string>Clock</string>
<string>Livestream with DVR support</string>
<key>url</key>
<string>https://wowza.jwplayer.com/live/jelly.stream/playlist.m3u8?DVR</string>
<string>http://tagesschau-lh.akamaihd.net/i/tagesschau_1@119231/master.m3u8</string>
</dict>
</array>
</dict>
Expand Down
5 changes: 2 additions & 3 deletions Demo/Sources/Medias/MediasViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

case 1: {
SRGMediaPlayerViewController *mediaPlayerViewController = [[SRGMediaPlayerViewController alloc] init];
[self presentViewController:mediaPlayerViewController animated:YES completion:^{
[mediaPlayerViewController.controller playURL:contentURL];
}];
[mediaPlayerViewController.controller playURL:contentURL];
[self presentViewController:mediaPlayerViewController animated:YES completion:nil];
break;
}

Expand Down
56 changes: 47 additions & 9 deletions Framework/Sources/Core/SRGMediaPlayerConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
// Amount of seconds at the end of a DVR stream assumed to correspond to live conditions.
OBJC_EXTERN NSTimeInterval const SRGMediaPlayerLiveDefaultTolerance;

/**
* @name Types
*/

/**
* Media types.
*/
Expand Down Expand Up @@ -88,21 +92,19 @@ typedef NS_ENUM(NSInteger, SRGMediaPlayerPlaybackState) {
};

/**
* Notification sent when the player state changes. Use the `SRGMediaPlayerPreviousPlaybackStateKey` to retrieve
* previous state information from the notification `userInfo` dictionary.
* @name Notifications
*/

/**
* Notification sent when the player state changes.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerPlaybackStateDidChangeNotification; // Notification name.
OBJC_EXTERN NSString * const SRGMediaPlayerPlaybackStateKey; // Key to access the current playback state as an `NSNumber` (wrapping an `SRGMediaPlayerPlaybackState` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousPlaybackStateKey; // Key to access the previous playback state as an `NSNumber` (wrapping an `SRGMediaPlayerPlaybackState` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousContentURLKey; // Key to access the previously played URL if it changed.
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousUserInfoKey; // Key to access the previous user information if it changed.

/**
* Notification sent when playback failed. Use the `SRGMediaPlayerErrorKey` to retrieve an `NSError` information
* from the notification `userInfo` dictionary).
*/
OBJC_EXTERN NSString * const SRGMediaPlayerPlaybackDidFailNotification; // Notification name.
OBJC_EXTERN NSString * const SRGMediaPlayerErrorKey; // Key to access error information.

/**
* Notification sent just before a seek is made (the player is already in the seeking state, though). Use the `SRGMediaPlayerSeekTimeKey`
Expand All @@ -112,24 +114,55 @@ OBJC_EXTERN NSString * const SRGMediaPlayerErrorKey;
* time is not received in a notification).
*/
OBJC_EXTERN NSString * const SRGMediaPlayerSeekNotification; // Notification name.
OBJC_EXTERN NSString * const SRGMediaPlayerSeekTimeKey; // Key to access the time to which the seek is made, as an `NSValue` (wrapping a `CMTime` value).

/**
* Notification sent when the picture in picture state changes.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerPictureInPictureStateDidChangeNotification;

/**
* Notification sent when the external playback is enabled or disabled.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerExternalPlaybackStateDidChangeNotification;

/**
* Notification sent when the current segment changes. Use the keys available below to retrieve information from
* the notification `userInfo`dictionary.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerSegmentDidStartNotification; // Notification sent when a segment starts.
OBJC_EXTERN NSString * const SRGMediaPlayerSegmentDidEndNotification; // Notification sent when a segment ends.

// Blocked segments skipping notifications.
/**
* Blocked segments skipping notifications.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerWillSkipBlockedSegmentNotification; // Notification sent when the player starts skipping a blocked segment.
OBJC_EXTERN NSString * const SRGMediaPlayerDidSkipBlockedSegmentNotification; // Notification sent when the player finishes skipping a blocked segment.

/**
* @name Notification user information keys
*/

/**
* Information available for `SRGMediaPlayerPlaybackStateDidChangeNotification`.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerPlaybackStateKey; // Key to access the current playback state as an `NSNumber` (wrapping an `SRGMediaPlayerPlaybackState` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousPlaybackStateKey; // Key to access the previous playback state as an `NSNumber` (wrapping an `SRGMediaPlayerPlaybackState` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousContentURLKey; // Key to access the previously played URL.
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousTimeRangeKey; // Key to access the previous time range as an `NSValue` (wrapping an `CMTimeRange` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousMediaTypeKey; // Key to access the previous media type as an `NSNumber` (wrapping an `SRGMediaPlayerMediaType` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousStreamTypeKey; // Key to access the previous stream type as an `NSNumber` (wrapping an `SRGMediaPlayerStreamType` value).
OBJC_EXTERN NSString * const SRGMediaPlayerPreviousUserInfoKey; // Key to access the previous user information.

/**
* Information available for `SRGMediaPlayerPlaybackDidFailNotification`.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerErrorKey; // Key to access error information.

/**
* Information available for `SRGMediaPlayerSeekNotification`.
*/
OBJC_EXTERN NSString * const SRGMediaPlayerSeekTimeKey; // Key to access the time to which the seek is made, as an `NSValue` (wrapping a `CMTime` value).

// Information available for all segment-related notifications.
OBJC_EXTERN NSString * const SRGMediaPlayerSegmentKey; // The involved segment as an `id<SRGSegment>` object.

Expand All @@ -141,8 +174,13 @@ OBJC_EXTERN NSString * const SRGMediaPlayerPreviousSegmentKey;

// Information available for `SRGMediaPlayerSegmentDidEndNotification`.
OBJC_EXTERN NSString * const SRGMediaPlayerNextSegmentKey; // The previously played segment, if any, as an `id<SRGSegment>` object.
OBJC_EXTERN NSString * const SRGMediaPlayerInterruptionKey; // Key to an `NSNumber` wrapping a boolean, set to `YES` iff the end notification results because segment playback was interrupted.

// Information available for `SRGMediaPlayerSegmentDidStartNotification`, `SRGMediaPlayerSegmentDidEndNotification` and `SRGMediaPlayerPlaybackStateDidChangeNotification`.
OBJC_EXTERN NSString * const SRGMediaPlayerSelectionKey; // Key to an `NSNumber` wrapping a boolean, set to `YES` iff the notification results from a segment selection.

// Information available for all notifications, except `SRGMediaPlayerPictureInPictureStateDidChangeNotification` and `SRGMediaPlayerExternalPlaybackStateDidChangeNotification`.
// For `SRGMediaPlayerPlaybackStateDidChangeNotification` notifications, this key is only present when the player returns to idle, and provides the last known playback position.
OBJC_EXPORT NSString * const SRGMediaPlayerLastPlaybackTimeKey; // Key to an `NSValue` wrapping a `CMTime` specifying the last playback position before the event occurred.

NS_ASSUME_NONNULL_END
27 changes: 21 additions & 6 deletions Framework/Sources/Core/SRGMediaPlayerConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,42 @@
NSTimeInterval const SRGMediaPlayerLiveDefaultTolerance = 30.; // Same tolerance as the built-in iOS player

NSString * const SRGMediaPlayerPlaybackStateDidChangeNotification = @"SRGMediaPlayerPlaybackStateDidChangeNotification";
NSString * const SRGMediaPlayerPlaybackStateKey = @"SRGMediaPlayerPlaybackStateKey";
NSString * const SRGMediaPlayerPreviousPlaybackStateKey = @"SRGMediaPlayerPreviousPlaybackStateKey";
NSString * const SRGMediaPlayerPreviousContentURLKey = @"SRGMediaPlayerPreviousContentURLKey";
NSString * const SRGMediaPlayerPreviousUserInfoKey = @"SRGMediaPlayerPreviousUserInfoKey";

NSString * const SRGMediaPlayerPlaybackDidFailNotification = @"SRGMediaPlayerPlaybackDidFailNotification";
NSString * const SRGMediaPlayerErrorKey = @"SRGMediaPlayerErrorKey";

NSString * const SRGMediaPlayerSeekNotification = @"SRGMediaPlayerSeekNotification";
NSString * const SRGMediaPlayerSeekTimeKey = @"SRGMediaPlayerSeekTimeKey";

NSString * const SRGMediaPlayerPictureInPictureStateDidChangeNotification = @"SRGMediaPlayerPictureInPictureStateDidChangeNotification";

NSString * const SRGMediaPlayerExternalPlaybackStateDidChangeNotification = @"SRGMediaPlayerExternalPlaybackStateDidChangeNotification";

NSString * const SRGMediaPlayerSegmentDidStartNotification = @"SRGMediaPlayerSegmentDidStartNotification";
NSString * const SRGMediaPlayerSegmentDidEndNotification = @"SRGMediaPlayerSegmentDidEndNotification";

NSString * const SRGMediaPlayerWillSkipBlockedSegmentNotification = @"SRGMediaPlayerWillSkipBlockedSegmentNotification";
NSString * const SRGMediaPlayerDidSkipBlockedSegmentNotification = @"SRGMediaPlayerDidSkipBlockedSegmentNotification";

NSString * const SRGMediaPlayerPlaybackStateKey = @"SRGMediaPlayerPlaybackStateKey";
NSString * const SRGMediaPlayerPreviousPlaybackStateKey = @"SRGMediaPlayerPreviousPlaybackStateKey";
NSString * const SRGMediaPlayerPreviousContentURLKey = @"SRGMediaPlayerPreviousContentURLKey";
NSString * const SRGMediaPlayerPreviousTimeRangeKey = @"SRGMediaPlayerPreviousTimeRangeKey";
NSString * const SRGMediaPlayerPreviousMediaTypeKey = @"SRGMediaPlayerPreviousMediaTypeKey";
NSString * const SRGMediaPlayerPreviousStreamTypeKey = @"SRGMediaPlayerPreviousStreamTypeKey";
NSString * const SRGMediaPlayerPreviousUserInfoKey = @"SRGMediaPlayerPreviousUserInfoKey";

NSString * const SRGMediaPlayerErrorKey = @"SRGMediaPlayerErrorKey";

NSString * const SRGMediaPlayerSeekTimeKey = @"SRGMediaPlayerSeekTimeKey";

NSString * const SRGMediaPlayerSegmentKey = @"SRGMediaPlayerSegmentKey";

NSString * const SRGMediaPlayerSelectedKey = @"SRGMediaPlayerSelectedKey";

NSString * const SRGMediaPlayerPreviousSegmentKey = @"SRGMediaPlayerPreviousSegmentKey";

NSString * const SRGMediaPlayerNextSegmentKey = @"SRGMediaPlayerNextSegmentKey";
NSString * const SRGMediaPlayerInterruptionKey = @"SRGMediaPlayerInterruptionKey";

NSString * const SRGMediaPlayerSelectionKey = @"SRGMediaPlayerSelectionKey";

NSString * const SRGMediaPlayerLastPlaybackTimeKey = @"SRGMediaPlayerLastPlaybackTimeKey";
20 changes: 20 additions & 0 deletions Framework/Sources/Helpers/AVPlayer+SRGMediaPlayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

#import <AVFoundation/AVFoundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface AVPlayer (SRGMediaPlayer)

/**
* Attempt to play the media immediately if possible (iOS 10), otherwise normally.
*/
- (void)srg_playImmediatelyIfPossible;

@end

NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions Framework/Sources/Helpers/AVPlayer+SRGMediaPlayer.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//

#import "AVPlayer+SRGMediaPlayer.h"

@implementation AVPlayer (SRGMediaPlayer)

// TODO: Remove when iOS 10 is the minimum required version.
- (void)srg_playImmediatelyIfPossible
{
if ([self respondsToSelector:@selector(playImmediatelyAtRate:)]) {
[self playImmediatelyAtRate:1.f];
}
else {
[self play];
}
}

@end
3 changes: 1 addition & 2 deletions Framework/Sources/Overlays/SRGAirplayButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ - (void)updateAppearanceForMediaPlayerController:(SRGMediaPlayerController *)med
self.hidden = YES;
}
else if (mediaPlayerController) {
BOOL allowsAirplayPlayback = mediaPlayerController.mediaType == SRGMediaPlayerMediaTypeAudio
|| (mediaPlayerController.mediaType == SRGMediaPlayerMediaTypeVideo && mediaPlayerController.allowsExternalNonMirroredPlayback);
BOOL allowsAirplayPlayback = mediaPlayerController.mediaType != SRGMediaPlayerMediaTypeVideo || mediaPlayerController.allowsExternalNonMirroredPlayback;
if (self.volumeView.areWirelessRoutesAvailable && allowsAirplayPlayback) {
airplayButton.tintColor = [AVAudioSession srg_isAirplayActive] ? self.activeTintColor : self.tintColor;
self.hidden = NO;
Expand Down
Loading

0 comments on commit 514d427

Please sign in to comment.