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.content.Context; | 7 import android.content.Context; |
8 import android.content.pm.PackageManager; | 8 import android.content.pm.PackageManager; |
9 import android.media.MediaMetadataRetriever; | 9 import android.media.MediaMetadataRetriever; |
10 import android.net.ConnectivityManager; | 10 import android.net.ConnectivityManager; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 MediaMetadataRetriever retriever = new MediaMetadataRetriever(); | 92 MediaMetadataRetriever retriever = new MediaMetadataRetriever(); |
93 try { | 93 try { |
94 Uri uri = Uri.parse(url); | 94 Uri uri = Uri.parse(url); |
95 String scheme = uri.getScheme(); | 95 String scheme = uri.getScheme(); |
96 if (scheme == null || scheme.equals("file")) { | 96 if (scheme == null || scheme.equals("file")) { |
97 File file = new File(uri.getPath()); | 97 File file = new File(uri.getPath()); |
98 String path = file.getAbsolutePath(); | 98 String path = file.getAbsolutePath(); |
99 if (file.exists() && (path.startsWith("/mnt/sdcard/") || | 99 if (file.exists() && (path.startsWith("/mnt/sdcard/") || |
100 path.startsWith("/sdcard/") || | 100 path.startsWith("/sdcard/") || |
101 path.startsWith(PathUtils.getExternalStorageDirectory())
)) { | 101 path.startsWith(PathUtils.getExternalStorageDirectory())
|| |
| 102 path.startsWith(context.getCacheDir().getAbsolutePath())
)) { |
102 retriever.setDataSource(path); | 103 retriever.setDataSource(path); |
103 } else { | 104 } else { |
104 Log.e(TAG, "Unable to read file: " + url); | |
105 return new MediaMetadata(durationInMilliseconds, width, heig
ht, success); | 105 return new MediaMetadata(durationInMilliseconds, width, heig
ht, success); |
106 } | 106 } |
107 } else { | 107 } else { |
108 HashMap<String, String> headersMap = new HashMap<String, String>
(); | 108 HashMap<String, String> headersMap = new HashMap<String, String>
(); |
109 if (!TextUtils.isEmpty(cookies)) { | 109 if (!TextUtils.isEmpty(cookies)) { |
110 headersMap.put("Cookie", cookies); | 110 headersMap.put("Cookie", cookies); |
111 } | 111 } |
112 retriever.setDataSource(url, headersMap); | 112 retriever.setDataSource(url, headersMap); |
113 } | 113 } |
114 String duration = retriever.extractMetadata( | 114 String duration = retriever.extractMetadata( |
(...skipping 10 matching lines...) Expand all Loading... |
125 height = Integer.parseInt(videoHeight); | 125 height = Integer.parseInt(videoHeight); |
126 success = true; | 126 success = true; |
127 } catch (IllegalArgumentException e) { | 127 } catch (IllegalArgumentException e) { |
128 Log.e(TAG, "Invalid url: " + e); | 128 Log.e(TAG, "Invalid url: " + e); |
129 } catch (RuntimeException e) { | 129 } catch (RuntimeException e) { |
130 Log.e(TAG, "Invalid url: " + e); | 130 Log.e(TAG, "Invalid url: " + e); |
131 } | 131 } |
132 return new MediaMetadata(durationInMilliseconds, width, height, success)
; | 132 return new MediaMetadata(durationInMilliseconds, width, height, success)
; |
133 } | 133 } |
134 } | 134 } |
OLD | NEW |