diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index 3562a64a06bb..1da78717e64e 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1404,11 +1404,11 @@ HTMLMediaElement::CurrentTime() const
return stream->StreamTimeToSeconds(stream->GetCurrentTime());
}
- if (mDecoder) {
+ if (mDefaultPlaybackStartPosition == 0.0 && mDecoder) {
return mDecoder->GetCurrentTime();
}
- return 0.0;
+ return mDefaultPlaybackStartPosition;
}
NS_IMETHODIMP HTMLMediaElement::GetCurrentTime(double* aCurrentTime)
@@ -1515,8 +1515,7 @@ HTMLMediaElement::Seek(double aTime,
}
if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) {
- LOG(LogLevel::Debug, ("%p SetCurrentTime(%f) failed: no source", this, aTime));
- aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+ mDefaultPlaybackStartPosition = aTime;
return;
}
@@ -2114,7 +2113,8 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed& aNo
mMediaStreamTrackListener(nullptr),
mElementInTreeState(ELEMENT_NOT_INTREE),
mHasUserInteraction(false),
- mFirstFrameLoaded(false)
+ mFirstFrameLoaded(false),
+ mDefaultPlaybackStartPosition(0.0)
{
if (!gMediaElementLog) {
gMediaElementLog = PR_NewLogModule("nsMediaElement");
@@ -3440,6 +3440,11 @@ void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
// We are a video element playing video so update the screen wakelock
NotifyOwnerDocumentActivityChangedInternal();
}
+
+ if (mDefaultPlaybackStartPosition > 0) {
+ SetCurrentTime(mDefaultPlaybackStartPosition);
+ mDefaultPlaybackStartPosition = 0.0;
+ }
}
void HTMLMediaElement::FirstFrameLoaded()
diff --git a/dom/html/HTMLMediaElement.h b/dom/html/HTMLMediaElement.h
index 15cc1280750b..b9c376e108ab 100644
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1516,6 +1516,11 @@ private:
// True if the first frame has been successfully loaded.
bool mFirstFrameLoaded;
+
+ // Media elements also have a default playback start position, which must
+ // initially be set to zero seconds. This time is used to allow the element to
+ // be seeked even before the media is loaded.
+ double mDefaultPlaybackStartPosition;
};
} // namespace dom