question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement startPosition prop to set the start time of a video

See original GitHub issue

Feature Request

Add a new prop for iOS and Android to be able to set the start time a video opens at. I am open to doing the PR for this, but per the contribution guide I’m opening an issue first.

Why it is needed

Sometimes users may want to have a video start at a time other than 0:00. It’s possible to manually run a .seek in the onLoad prop, but on Android in particular for bigger video files, there is noticeable lag in this starting.

Possible implementation

In my local project we used patch-package to make this work on android. In ReactExoplayerView.java in initializePlayerSource, the start time can be used if resumePosition is not present.

Logic to set the start time in getVideoTrackInfoFromManifest would likely be needed to initialize start time as well, something like final long startTime = (this.startTime > 0 ? this.startTime : this.contentStartTime) * 1000 - 100; // s -> ms with 100ms offset But I don’t understand that section quite as well.

I haven’t looked into the swift side yet and don’t have as much knowledge there, but I believe in the setter that would be created, you could set pendingSeek and pendingSeekTime if startTime is passed in, then handleReadyToPlay would automatically seek to the correct time when the player is ready.

Code sample

After setting the startTime variable, snippet from our android patch-package:

@@ -624,11 +625,14 @@ class ReactExoplayerView extends FrameLayout implements
             }
         }
 
-        boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
-        if (haveResumePosition) {
+        boolean useStartTime = this.startTime > 0;
+        boolean useResumePosition = resumeWindow != C.INDEX_UNSET && resumePosition > 0;
+        if (useResumePosition) {
             player.seekTo(resumeWindow, resumePosition);
+        } else if (useStartTime) {
+            player.seekTo(this.startTime * 1000); // sec to ms
         }
-        player.prepare(mediaSource, !haveResumePosition, false);
+        player.prepare(mediaSource, !useResumePosition && !useStartTime, false);
         playerNeedsSource = false;

For iOS, I haven’t done much native work but something like this may work

@objc func setStartTime(_ startTime:Float) { if startTime > 0 { _pendingSeek = true _pendingSeekTime = startTime } }

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
freeboubcommented, Aug 1, 2022

Heum, you are right. I don’t think this ‘contentStartTime’ is a good feature then … I can implement it next week for android, but I need help to support ios 😕

0reactions
AlkanVcommented, Nov 1, 2022

@freeboub any update on this? i also need similar feature; ability to start a video from given position.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Start HTML5 video at a particular position when loading?
When the page loads, it just starts playing from beginning. However if I call this during playback like after some time, it works...
Read more >
HTML DOM Video played Property - W3Schools
Represents the played parts of the video. TimeRanges Object Properties: length - get the number of played ranges in the video; start(index) -...
Read more >
Docs | GSAP | Timeline - GreenSock
Positioning animations in a timeline · Absolute time (in seconds) measured from the start of the timeline, as a number like 3 //...
Read more >
Responsive and Progressive Video Loading in React
We can use the attribute onLoadedData to determine when the loading is complete. const Video = props => { const [isVideoLoaded, setIsVideoLoaded] =...
Read more >
Create Scrolling Text in ProPresenter 7 | Video Tutorial
In this video, we're going to learn how to implement scrolling text by creating ... But if we would set this to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found