Mohsen Kamrani
Mohsen Kamrani

Reputation: 7457

Show the thumbnail of a video with http

I want to show the thumbnail videos in an ImageView. The videos are uploaded by the users and stored on a server. At the moment I have not set up any mechanism to store and upload the videos so I'm testing this with a sample video file that is accessed using http protocol. But, this post says that

ContentResolver.query returns null if the uri scheme is not of the form content://

Is my approach wrong? Is it possible to use this approach with http?

This is my test code:

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();
    }
  }
}

Upvotes: 0

Views: 67

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007276

There are problems with your code.

Your getRealPathFromURI() is broken in general on ~600 million Android devices at the present time (everything that runs Android 4.4 or higher), for any Uri value, let alone the one that you are trying. A Uri is not a file. Wherever you got the Uri from, it may not point to something from MediaStore. Even if it is something from the MediaStore, you will not get a file path from MediaStore via DATA. And even if it were possible to get a file path, you might not have access to that file (e.g., it is stored on removable storage).

MediaStore is an index of local content. Hence, in your specific case, unless your Android device is running the Web server hosted at download.wavetlan.com, the content at your URL is not local, and so MediaStore will know nothing about it.

Please have your server generate a thumbnail, and then you can use an image loading library like Picasso to get that thumbnail.

Upvotes: 1

Related Questions