使用http

时间:2015-11-09 21:12:27

标签: android video

我想在ImageView中显示缩略图视频。视频由用户上传并存储在服务器上。目前我还没有设置任何存储和上传视频的机制,所以我正在测试这个使用http协议访问的示例视频文件。但是,this帖子说

  

如果uri方案的格式不是内容,则ContentResolver.query返回null://

我的方法有误吗?是否可以将此方法与http?

一起使用

这是我的测试代码:

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.testlayout);
    Uri uri = Uri.parse("http://download.wavetlan.com/SVV/Media/HTTP/BlackBerry.3gp");
    Log.i("m",getRealPathFromURI(this, uri));
}
public String getRealPathFromURI(Context context, Uri contentUri) {
  Cursor cursor = null;
  try { 
    String[] proj = { MediaStore.Images.Media.DATA };
    cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
    if (cursor == null)
    {
        Log.i("m","null");
        return "";
    }
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

1 个答案:

答案 0 :(得分:1)

您的代码存在问题。

对于任何Route::get('/', function () { return view('home'); }); Route::get('/about', function () { return view('about'); }); Route::get('/contact', function () { return view('contact'); }); 值,您的getRealPathFromURI()在目前约有6亿台Android设备(运行Android 4.4或更高版本的所有设备)上一般会被打破,更不用说您正在尝试的那个。 A Uri is not a file。无论您从Uri获得Uri,都可能无法指向MediaStore中的内容。即使它来自MediaStore,您也无法通过MediaStoreDATA获取文件路径。即使有可能获得文件路径,您也可能无法访问该文件(例如,它存储在removable storage上)。

MediaStore是本地内容的索引。因此,在您的特定情况下,除非您的Android设备正在运行download.wavetlan.com托管的网络服务器,否则您网址上的内容不是本地内容,因此MediaStore对此一无所知。

请让您的服务器生成缩略图,然后您可以使用image loading library之类Picasso来获取该缩略图。

相关问题