Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.pm.PackageManager; | 9 import android.content.pm.PackageManager; |
| 10 import android.media.MediaMetadataRetriever; | 10 import android.media.MediaMetadataRetriever; |
| 11 import android.net.ConnectivityManager; | 11 import android.net.ConnectivityManager; |
| 12 import android.net.NetworkInfo; | 12 import android.net.NetworkInfo; |
| 13 import android.net.Uri; | |
| 13 import android.os.ParcelFileDescriptor; | 14 import android.os.ParcelFileDescriptor; |
| 14 import android.text.TextUtils; | 15 import android.text.TextUtils; |
| 15 | 16 |
| 16 import org.chromium.base.Log; | 17 import org.chromium.base.Log; |
| 17 import org.chromium.base.PathUtils; | 18 import org.chromium.base.PathUtils; |
| 18 import org.chromium.base.VisibleForTesting; | 19 import org.chromium.base.VisibleForTesting; |
| 19 import org.chromium.base.annotations.CalledByNative; | 20 import org.chromium.base.annotations.CalledByNative; |
| 20 import org.chromium.base.annotations.JNINamespace; | 21 import org.chromium.base.annotations.JNINamespace; |
| 21 | 22 |
| 22 import java.io.File; | 23 import java.io.File; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 return false; | 222 return false; |
| 222 } | 223 } |
| 223 try { | 224 try { |
| 224 configure(file.getAbsolutePath()); | 225 configure(file.getAbsolutePath()); |
| 225 return true; | 226 return true; |
| 226 } catch (RuntimeException e) { | 227 } catch (RuntimeException e) { |
| 227 Log.e(TAG, "Error configuring data source: %s", e.getMessage()); | 228 Log.e(TAG, "Error configuring data source: %s", e.getMessage()); |
| 228 return false; | 229 return false; |
| 229 } | 230 } |
| 230 } | 231 } |
| 232 if (scheme.equals("content")) { | |
| 233 try { | |
| 234 configure(context, Uri.parse(uri.toString())); | |
| 235 return true; | |
| 236 } catch (RuntimeException e) { | |
| 237 Log.e(TAG, "Error configuring data source: %s", e.getMessage()); | |
|
qinmin
2016/01/25 18:58:56
nit: you can simply do Log.e(TAG, "Error configuri
horo
2016/01/25 22:58:41
Done.
| |
| 238 return false; | |
| 239 } | |
| 240 } | |
| 231 if (uri.getPath() != null && uri.getPath().endsWith(".m3u8")) { | 241 if (uri.getPath() != null && uri.getPath().endsWith(".m3u8")) { |
| 232 // MediaMetadataRetriever does not work with HLS correctly. | 242 // MediaMetadataRetriever does not work with HLS correctly. |
| 233 return false; | 243 return false; |
| 234 } | 244 } |
| 235 final String host = uri.getHost(); | 245 final String host = uri.getHost(); |
| 236 if (!isLoopbackAddress(host) && !isNetworkReliable(context)) { | 246 if (!isLoopbackAddress(host) && !isNetworkReliable(context)) { |
| 237 Log.w(TAG, "non-file URI can't be read due to unsuitable network con ditions"); | 247 Log.w(TAG, "non-file URI can't be read due to unsuitable network con ditions"); |
| 238 return false; | 248 return false; |
| 239 } | 249 } |
| 240 Map<String, String> headersMap = new HashMap<String, String>(); | 250 Map<String, String> headersMap = new HashMap<String, String>(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 @VisibleForTesting | 400 @VisibleForTesting |
| 391 void configure(String url, Map<String, String> headers) { | 401 void configure(String url, Map<String, String> headers) { |
| 392 mRetriever.setDataSource(url, headers); | 402 mRetriever.setDataSource(url, headers); |
| 393 } | 403 } |
| 394 | 404 |
| 395 @VisibleForTesting | 405 @VisibleForTesting |
| 396 void configure(String path) { | 406 void configure(String path) { |
| 397 mRetriever.setDataSource(path); | 407 mRetriever.setDataSource(path); |
| 398 } | 408 } |
| 399 | 409 |
| 410 void configure(Context context, Uri uri) { | |
| 411 mRetriever.setDataSource(context, uri); | |
| 412 } | |
| 413 | |
| 400 @VisibleForTesting | 414 @VisibleForTesting |
| 401 String extractMetadata(int key) { | 415 String extractMetadata(int key) { |
| 402 return mRetriever.extractMetadata(key); | 416 return mRetriever.extractMetadata(key); |
| 403 } | 417 } |
| 404 } | 418 } |
| OLD | NEW |