Skip to content

Commit

Permalink
feat: rebuffer to live (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bowlerr authored Aug 29, 2023
1 parent 9ce7e60 commit bf136e1
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
player?.setLiveLowLatencyEnabled(liveLowLatency)
}

fun setRebufferToLive(rebufferToLive: Boolean) {
player?.setRebufferToLive(rebufferToLive)
}

fun setPlaybackRate(playbackRate: Double) {
player?.playbackRate = playbackRate.toFloat()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ class AmazonIvsViewManager : SimpleViewManager<AmazonIvsView>() {
view.setLiveLowLatency(liveLowLatency)
}

@ReactProp(name = "rebufferToLive")
fun setRebufferToLive(view: AmazonIvsView, rebufferToLive: Boolean) {
view.setRebufferToLive(rebufferToLive)
}

@ReactProp(name = "playbackRate")
fun setPlaybackRate(view: AmazonIvsView, playbackRate: Double) {
view.setPlaybackRate(playbackRate)
Expand Down
7 changes: 7 additions & 0 deletions docs/ivs-player-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ Only works with live streams.

type: `boolean`

### rebufferToLive _(optional)_

Enable skipping to the live edge on a rebuffer. Note this can cause video content and content associated with it such as timed metadata to be skipped.

default: `false`
type: `boolean`

### onRebuffering _(optional)_

Indicates that the player is buffering from a previous PLAYING state.
Expand Down
15 changes: 15 additions & 0 deletions e2e/playgroundPlayer.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,21 @@ describe('Playground player', () => {
await expectNativePlayerToBeVisible(); // Not a crash
});

it("Player doesn't crash after changing rebufferToLive property", async () => {
await expectNativePlayerToBeVisible();
await togglePlayPauseVideo();

await waitFor(element(by.id('settingsIcon')))
.toBeVisible()
.withTimeout(TIMEOUT);
await element(by.id('settingsIcon')).tap();
await scrollToModalBottom();
await element(by.id('rebufferToLive')).tap();
await element(by.id('closeIcon')).tap();

await expectNativePlayerToBeVisible(); // Not a crash
});

it("Player doesn't crash after changing autoQuality property", async () => {
await expectNativePlayerToBeVisible();
await togglePlayPauseVideo();
Expand Down
8 changes: 8 additions & 0 deletions example/src/screens/PlaygroundExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function PlaygroundExample() {
const [buffering, setBuffering] = useState(false);
const [duration, setDuration] = useState<number | null>(null);
const [liveLowLatency, setLiveLowLatency] = useState(true);
const [rebufferToLive, setRebufferToLive] = useState(false);
const [playbackRate, setPlaybackRate] = useState(1);
const [logLevel, setLogLevel] = useState(LogLevel.IVSLogLevelError);
const [progressInterval, setProgressInterval] = useState(1);
Expand Down Expand Up @@ -161,6 +162,7 @@ export default function PlaygroundExample() {
muted={muted}
autoplay={autoplay}
liveLowLatency={liveLowLatency}
rebufferToLive={rebufferToLive}
streamUrl={url}
logLevel={logLevel}
initialBufferDuration={initialBufferDuration}
Expand Down Expand Up @@ -397,6 +399,12 @@ export default function PlaygroundExample() {
value={liveLowLatency}
testID="liveLowLatency"
/>
<SettingsSwitchItem
label="Rebuffer To Live"
onValueChange={setRebufferToLive}
value={rebufferToLive}
testID="rebufferToLive"
/>
<SettingsSwitchItem
label="Pause in background"
value={pauseInBackground}
Expand Down
1 change: 1 addition & 0 deletions ios/AmazonIvsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ @interface RCT_EXTERN_MODULE(AmazonIvsManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(muted, BOOL)
RCT_EXPORT_VIEW_PROPERTY(loop, BOOL)
RCT_EXPORT_VIEW_PROPERTY(liveLowLatency, BOOL)
RCT_EXPORT_VIEW_PROPERTY(rebufferToLive, BOOL)
RCT_EXPORT_VIEW_PROPERTY(quality, NSDictionary)
RCT_EXPORT_VIEW_PROPERTY(initialBufferDuration, double)
RCT_EXPORT_VIEW_PROPERTY(autoMaxQuality, NSDictionary)
Expand Down
9 changes: 8 additions & 1 deletion ios/AmazonIvsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AmazonIvsView: UIView, IVSPlayer.Delegate {
self.muted = player.muted
self.loop = player.looping
self.liveLowLatency = player.isLiveLowLatency
self.rebufferToLive = false;
self.autoQualityMode = player.autoQualityMode
self.pipEnabled = false
self.playbackRate = Double(player.playbackRate)
Expand Down Expand Up @@ -127,6 +128,12 @@ class AmazonIvsView: UIView, IVSPlayer.Delegate {
}
}

@objc var rebufferToLive: Bool {
didSet {
player.setRebufferToLive(rebufferToLive)
}
}

@objc var quality: NSDictionary? {
didSet {
let newQuality = findQuality(quality: quality)
Expand Down Expand Up @@ -264,7 +271,7 @@ class AmazonIvsView: UIView, IVSPlayer.Delegate {
let parsedTime = CMTimeMakeWithSeconds(position, preferredTimescale: 1000000)
player.seek(to: parsedTime)
}

@objc func setOrigin(origin: NSString){
let url = URL(string: origin as String)
player.setOrigin(url)
Expand Down
1 change: 1 addition & 0 deletions src/IVSPlayer.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare type Props = {|
streamUrl?: string,
resizeMode?: ResizeMode,
liveLowLatency?: boolean,
rebufferToLive?: boolean,
playbackRate?: number,
logLevel?: LogLevel,
progressInterval?: number,
Expand Down
4 changes: 4 additions & 0 deletions src/IVSPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type IVSPlayerProps = {
muted?: boolean;
loop?: boolean;
liveLowLatency?: boolean;
rebufferToLive?: boolean;
playbackRate?: number;
streamUrl?: string;
resizeMode?: ResizeMode;
Expand Down Expand Up @@ -85,6 +86,7 @@ export type Props = {
autoplay?: boolean;
streamUrl?: string;
liveLowLatency?: boolean;
rebufferToLive?: boolean;
playbackRate?: number;
logLevel?: LogLevel;
resizeMode?: ResizeMode;
Expand Down Expand Up @@ -133,6 +135,7 @@ const IVSPlayerContainer = React.forwardRef<IVSPlayerRef, Props>(
resizeMode,
autoplay = true,
liveLowLatency,
rebufferToLive,
playbackRate,
pipEnabled,
logLevel,
Expand Down Expand Up @@ -341,6 +344,7 @@ const IVSPlayerContainer = React.forwardRef<IVSPlayerRef, Props>(
muted={muted}
loop={loop}
liveLowLatency={liveLowLatency}
rebufferToLive={rebufferToLive}
style={styles.mediaPlayer}
ref={mediaPlayerRef}
playbackRate={playbackRate}
Expand Down

0 comments on commit bf136e1

Please sign in to comment.