Skip to content

Commit

Permalink
Start RemotePlayback from current time (CAF version)
Browse files Browse the repository at this point in the history
This is the CAF-version of CL https://crrev.com/c/1263615

The original CL description is as follows:

Currently, the new RemotePlayback path always plays videos from the
beginning. It also disregard the current play/pause state and always
autoplays.

This CL fixes both issues by delaying the call to load, until we get our
first seek or play command, and by loading the video with the current
time.

The case when a video that has was never played is cast will be
re-examined in a follow up CL (the user intent when casting a video is
probably to watch it, so it is probably best to start playback, rather
than to force the user to cast and then press play).


Bug: 711860
Change-Id: I8f039f7607519a44712554e2907551d7177c425c
Reviewed-on: https://chromium-review.googlesource.com/c/1363974
Commit-Queue: Zhiqiang Zhang <zqzhang@chromium.org>
Reviewed-by: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614166}
  • Loading branch information
Zhiqiang Zhang authored and Commit Bot committed Dec 5, 2018
1 parent 5f3baa7 commit 51ffd9d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.chromium.chrome.browser.media.router.caf.remoting;

import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaStatus;
import com.google.android.gms.cast.framework.media.RemoteMediaClient;

Expand All @@ -18,11 +19,14 @@ public class FlingingControllerAdapter implements FlingingController, MediaContr
private static final String TAG = "FlingCtrlAdptr";

private final RemotingSessionController mSessionController;
private final String mMediaUrl;
private MediaStatusObserver mMediaStatusObserver;
private long mCachedApproximateCurrentTime;
private boolean mLoaded;

FlingingControllerAdapter(RemotingSessionController sessionController) {
FlingingControllerAdapter(RemotingSessionController sessionController, String mediaUrl) {
mSessionController = sessionController;
mMediaUrl = mediaUrl;
}

////////////////////////////////////////////
Expand Down Expand Up @@ -59,13 +63,32 @@ public long getApproximateCurrentTime() {
// FlingingController implementation end
////////////////////////////////////////////

/** Starts loading the media URL, from the given position. */
public void load(long position) {
if (!mSessionController.isConnected()) return;

mLoaded = true;

MediaInfo mediaInfo = new MediaInfo.Builder(mMediaUrl)
.setContentType("*/*")
.setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
.build();
mSessionController.getRemoteMediaClient().load(mediaInfo, /* autoplay= */ true, position);
}

////////////////////////////////////////////
// MediaController implementation begin
////////////////////////////////////////////

@Override
public void play() {
if (!mSessionController.isConnected()) return;

if (!mLoaded) {
load(/* position= */ 0);
return;
}

mSessionController.getRemoteMediaClient().play().setResultCallback(
this ::onMediaCommandResult);
}
Expand Down Expand Up @@ -94,6 +117,12 @@ public void setVolume(double volume) {
@Override
public void seek(long position) {
if (!mSessionController.isConnected()) return;

if (!mLoaded) {
load(position);
return;
}

mSessionController.getRemoteMediaClient().seek(position).setResultCallback(
this ::onMediaCommandResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.chromium.chrome.browser.media.router.caf.remoting;

import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.framework.CastSession;

import org.chromium.base.Log;
Expand All @@ -21,7 +20,6 @@ public class RemotingSessionController extends BaseSessionController {
private FlingingControllerAdapter mFlingingControllerAdapter;
RemotingSessionController(CafBaseMediaRouteProvider provider) {
super(provider);
mFlingingControllerAdapter = new FlingingControllerAdapter(this);
}

@Override
Expand All @@ -40,8 +38,8 @@ public void attachToCastSession(CastSession session) {
@Override
public void onSessionStarted() {
super.onSessionStarted();
getRemoteMediaClient().load(
new MediaInfo.Builder(((RemotingMediaSource) getSource()).getMediaUrl()).build());
RemotingMediaSource source = (RemotingMediaSource) getSource();
mFlingingControllerAdapter = new FlingingControllerAdapter(this, source.getMediaUrl());
}

@Override
Expand Down

0 comments on commit 51ffd9d

Please sign in to comment.