[英]Android: Display a .gif from the internet
我知道,在Android中,可以在Movie對象中存儲.gif文件,然后使用setTime()操作框架。 當我嘗試從資源中顯示.gif時,它工作正常。
不幸的是,從URL顯示.gif更不成功。 這是相關代碼:
public void setMovieURL(String url) throws MalformedURLException, IOException {
movie = Movie.decodeStream(fetch(url));
}
private static InputStream getStreamFromURL(String url) throws MalformedURLException, IOException {
return fetch(url);
}
public static InputStream fetch(String address) throws MalformedURLException,IOException {
URL url = new URL(address);
InputStream content = url.openStream();
return content;
}
Movie設置為非空值,但其高度,寬度和持續時間均為0.在InputStream中觸發IOException(因為調用了reset()),但它也在InputStream中捕獲。 這可能是也可能不相關。
我不明白為什么那不起作用。 我在我的智慧結束,我的替代方案是下載文件並保存它,或處理字節數組。
即使從內部存儲中的文件中讀取gif(而不是從資源中),也會發生相同的情況。 解決它的方法 - 下載到byte [],並使用ByteArrayInputStream來初始化電影。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.