mirror of
https://github.com/androidx/media.git
synced 2025-05-05 06:30:24 +08:00
Move getUserAgent from DemoUtil to library's Util.
This commit is contained in:
parent
6cb46e4549
commit
1d528b80ea
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user