Merge pull request #121 from google/dev

dev -> dev-l
This commit is contained in:
ojw28 2014-11-05 17:15:39 +00:00
commit e6c7e29647
8 changed files with 39 additions and 7 deletions

View File

@ -28,6 +28,9 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
@ -50,6 +53,13 @@ public class DemoUtil {
public static final boolean EXPOSE_EXPERIMENTAL_FEATURES = false;
private static final CookieManager defaultCookieManager;
static {
defaultCookieManager = new CookieManager();
defaultCookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
}
public static String getUserAgent(Context context) {
String versionName;
try {
@ -105,4 +115,11 @@ public class DemoUtil {
return bytes;
}
public static void setDefaultCookieManager() {
CookieHandler currentHandler = CookieHandler.getDefault();
if (currentHandler != defaultCookieManager) {
CookieHandler.setDefault(defaultCookieManager);
}
}
}

View File

@ -127,6 +127,8 @@ public class FullPlayerActivity extends Activity implements SurfaceHolder.Callba
videoButton = (Button) findViewById(R.id.video_controls);
audioButton = (Button) findViewById(R.id.audio_controls);
textButton = (Button) findViewById(R.id.text_controls);
DemoUtil.setDefaultCookieManager();
}
@Override

View File

@ -97,7 +97,7 @@ public class DashVodRendererBuilder implements RendererBuilder,
this.callback = callback;
MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser();
ManifestFetcher<MediaPresentationDescription> manifestFetcher =
new ManifestFetcher<MediaPresentationDescription>(parser, contentId, url);
new ManifestFetcher<MediaPresentationDescription>(parser, contentId, url, userAgent);
manifestFetcher.singleLoad(player.getMainHandler().getLooper(), this);
}

View File

@ -92,7 +92,7 @@ public class SmoothStreamingRendererBuilder implements RendererBuilder,
this.callback = callback;
SmoothStreamingManifestParser parser = new SmoothStreamingManifestParser();
manifestFetcher = new ManifestFetcher<SmoothStreamingManifest>(parser, contentId,
url + "/Manifest");
url + "/Manifest", userAgent);
manifestFetcher.singleLoad(player.getMainHandler().getLooper(), this);
}

View File

@ -77,7 +77,7 @@ import java.util.ArrayList;
this.callback = callback;
MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser();
ManifestFetcher<MediaPresentationDescription> manifestFetcher =
new ManifestFetcher<MediaPresentationDescription>(parser, contentId, url);
new ManifestFetcher<MediaPresentationDescription>(parser, contentId, url, userAgent);
manifestFetcher.singleLoad(playerActivity.getMainLooper(), this);
}

View File

@ -113,6 +113,8 @@ public class SimplePlayerActivity extends Activity implements SurfaceHolder.Call
shutterView = findViewById(R.id.shutter);
surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
surfaceView.getHolder().addCallback(this);
DemoUtil.setDefaultCookieManager();
}
@Override

View File

@ -77,7 +77,7 @@ import java.util.ArrayList;
this.callback = callback;
SmoothStreamingManifestParser parser = new SmoothStreamingManifestParser();
manifestFetcher = new ManifestFetcher<SmoothStreamingManifest>(parser, contentId,
url + "/Manifest");
url + "/Manifest", userAgent);
manifestFetcher.singleLoad(playerActivity.getMainLooper(), this);
}

View File

@ -63,6 +63,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
/* package */ final ManifestParser<T> parser;
/* package */ final String manifestUrl;
/* package */ final String contentId;
/* package */ final String userAgent;
private int enabledCount;
private Loader loader;
@ -79,11 +80,14 @@ public class ManifestFetcher<T> implements Loader.Callback {
* @param parser A parser to parse the loaded manifest data.
* @param contentId The content id of the content being loaded. May be null.
* @param manifestUrl The manifest location.
* @param userAgent The User-Agent string that should be used.
*/
public ManifestFetcher(ManifestParser<T> parser, String contentId, String manifestUrl) {
public ManifestFetcher(ManifestParser<T> parser, String contentId, String manifestUrl,
String userAgent) {
this.parser = parser;
this.contentId = contentId;
this.manifestUrl = manifestUrl;
this.userAgent = userAgent;
}
/**
@ -167,7 +171,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
loader = new Loader("manifestLoader");
}
if (!loader.isLoading()) {
currentLoadable = new ManifestLoadable();
currentLoadable = new ManifestLoadable(userAgent);
loader.startLoading(currentLoadable, this);
}
}
@ -217,7 +221,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
this.callbackLooper = callbackLooper;
this.wrappedCallback = wrappedCallback;
singleUseLoader = new Loader("manifestLoader:single");
singleUseLoadable = new ManifestLoadable();
singleUseLoadable = new ManifestLoadable(userAgent);
}
public void startLoading() {
@ -265,9 +269,15 @@ public class ManifestFetcher<T> implements Loader.Callback {
private static final int TIMEOUT_MILLIS = 10000;
private final String userAgent;
/* package */ volatile T result;
private volatile boolean isCanceled;
public ManifestLoadable(String userAgent) {
this.userAgent = userAgent;
}
@Override
public void cancelLoad() {
// We don't actually cancel anything, but we need to record the cancellation so that
@ -302,6 +312,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
connection.setConnectTimeout(TIMEOUT_MILLIS);
connection.setReadTimeout(TIMEOUT_MILLIS);
connection.setDoOutput(false);
connection.setRequestProperty("User-Agent", userAgent);
connection.connect();
return connection;
}