Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
604 views
in Technique[技术] by (71.8m points)

javascript - Netflix video player in Chrome - how to seek?

I have been unable to figure out how to do a video seek (automatically advance to a certain point in the video) in the Netflix video player running in Chrome. The currentTime property can be read but not set in the Netflix player, and when set, immediately triggers the error "Whoops! Something went wrong.". Other actions such as Play and Pause work quite well. For example, you can try the following:

  1. Log into Netflix (from Google Chrome) and go to the movie Armageddon.
  2. After the movie loads, pause it if it starts playing.
  3. Open the Chrome Developer Tools panel. Go to the Console tab.
  4. Paste the following snippet into the console and hit <ENTER>:

var video = document.evaluate('//*[@id="5670317"]/video',document).iterateNext()

Note: The id value is specific to Armageddon. If you choose a different movie, which is fine, change the id as per the id in the URL of that movie.

  1. Enter the following and then press <Enter>: video.play(). Observe that the video resumes playing.

Simple enough, but how to make the video auto-advance to a specific point in the video? You may want to refer to this doc. Obviously you can manually seek by dragging the video player slider from left to right and release it someplace. You may wish to discover which method or event is called when you do this, and simulate that. I haven't had luck thus far.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like netflix changed player api. Its what I found:

const videoPlayer = netflix
  .appContext
  .state
  .playerApp
  .getAPI()
  .videoPlayer

// Getting player id
const playerSessionId = videoPlayer
  .getAllPlayerSessionIds()[0]

const player = videoPlayer
  .getVideoPlayerBySessionId(playerSessionId)

Now you can use full player API. For example player.seek or player.getCurrentTime or player.pause, etc...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...