thumbnail returns null on android above version 4.0

别来无恙 提交于 2019-12-11 16:08:14

问题


I am getting the samethis issue

public class MainActivity extends Activity 
{


    ImageView imgVie;

    Bitmap bmp,extBmp;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        imgVie = (ImageView)findViewById(R.id.imageView1);          
        String path =   "http://202.65.154.108:8080/VODStream/lokesh.stream.mp4";
        bmp = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.FULL_SCREEN_KIND);

        if(bmp!=null)
        {

            extBmp =    ThumbnailUtils.extractThumbnail(bmp, 300, 300);
            imgVie.setImageBitmap(extBmp);
        }

        if(bmp==null)
        {
            Toast.makeText(getApplicationContext(), "Sorry your bitmap returns null", Toast.LENGTH_LONG).show();
        }
    }



}

when run this application in nexus4s its entering into if condition.In all other phones it moving to else. do you have any suggestions.


回答1:


1)- Sometime if video quality is poor , video is corrupt or format is not supported it returns null bitmap.

2)- createVideoThumbnail(String filePath, int kind) supports MINI_KIND or MICRO_KIND as kind only in 4.0+.

see http://developer.android.com/reference/android/media/ThumbnailUtils.html. try one of those...

3)- Some devices can't play and can't create thumbnails for videos, that placed on internal memory. Check it, and move your video to SD Card before thumbnails creating.

4)Check your path of the file.




回答2:


If your video is on the external storage requires permission <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />



来源:https://stackoverflow.com/questions/27164353/thumbnail-returns-null-on-android-above-version-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!