2012-08-07 136 views
0

我想從android應用中的Url獲取兆字節的視頻大小。我有一個播放器在應用內播放視頻。我想在播放器旁邊顯示當前的視頻大小。所以一個例子是我23MB。如果視頻是23毫克,比我在23MB視頻旁邊的文字要多。我嘗試瞭解所有的android mp.get函數,但無法找到Iam正在尋找的東西。請幫忙。也許我錯過了Android中的一個功能。或者mayber有一種方法可以幫助實現這一點。謝謝。獲取以MB爲單位的視頻大小Android

回答

0

HTTP content-length標頭的值將提供正在下載的文件的大小。

查看URLConnection.getHeaderField(String key)HttpMessage.getFirstHeader(String name),具體取決於您的服務器訪問代碼。

+0

我會研究這個。謝謝 – 2012-08-07 06:01:44

+0

好吧,我得到它的工作。但花了一個小時研究。 這是可用的代碼。 int lenghtOfFile = 0; \t \t \t \t嘗試{ URL url = new URL(uri.toString()); URLConnection conexion = url.openConnection(); conexion.connect(); lenghtOfFile = conexion.getContentLength(); } \t \t catch(Exception e){ e.printStackTrace(); } \t \t \t TextView p =(TextView)findViewById(R.id.videoBuffer); p =(TextView)findViewById(R.id.videoBuffer); \t \t p.setText(「」+ lenghtOfFile); – 2012-08-07 06:47:45

0
Try this will work in case the http server is giving the file size 

URL myUrl = new URL("http://your_url.com/file.mp3"); 
URLConnection urlConnection = myUrl.openConnection(); 
urlConnection.connect(); 
int file_size = urlConnection.getContentLength(); 
    file_size = file_size /1024; 

Or second Version try this. 

URL myUrl = new URL("http://your_url.com/file.mp3"); 
myConnection = myUrl.openConnection(); 
List headersize = myConnection.getHeaderFields().get("content-Lenght"); 
+0

Oww。我剛剛開始工作併發布了適用於我的代碼。不管怎麼說,還是要謝謝你。 – 2012-08-07 06:48:52

相關問題