Commit 1d528b80 by Oliver Woodman

Move getUserAgent from DemoUtil to library's Util.

parent 6cb46e45
......@@ -56,19 +56,6 @@ public class DemoUtil {
defaultCookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
}
public static String getUserAgent(Context context) {
String versionName;
try {
String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
versionName = info.versionName;
} catch (NameNotFoundException e) {
versionName = "?";
}
return "ExoPlayerDemo/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE +
") " + "ExoPlayerLib/" + ExoPlayerLibraryInfo.VERSION;
}
public static byte[] executePost(String url, byte[] data, Map<String, String> requestProperties)
throws MalformedURLException, IOException {
HttpURLConnection urlConnection = null;
......
......@@ -219,7 +219,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
// Internal methods
private RendererBuilder getRendererBuilder() {
String userAgent = DemoUtil.getUserAgent(this);
String userAgent = Util.getUserAgent(this, "ExoPlayerDemo");
switch (contentType) {
case DemoUtil.TYPE_SS:
return new SmoothStreamingRendererBuilder(userAgent, contentUri.toString(),
......
......@@ -16,9 +16,14 @@
package com.google.android.exoplayer.util;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.ExoPlayerLibraryInfo;
import com.google.android.exoplayer.upstream.DataSource;
import com.google.android.exoplayer.upstream.DataSpec;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.text.TextUtils;
import java.io.IOException;
......@@ -495,4 +500,24 @@ public final class Util {
return result;
}
/**
* Returns a user agent string based on the given application name and the library version.
*
* @param context A valid context of the calling application.
* @param applicationName String that will be prefix'ed to the generated user agent.
* @return A user agent string generated using the applicationName and the library version.
*/
public static String getUserAgent(Context context, String applicationName) {
String versionName;
try {
String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
versionName = info.versionName;
} catch (NameNotFoundException e) {
versionName = "?";
}
return applicationName + "/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE
+ ") " + "ExoPlayerLib/" + ExoPlayerLibraryInfo.VERSION;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment