【问题标题】:Video thumbnail return null视频缩略图返回 null
【发布时间】:2013-10-14 04:53:30
【问题描述】:

我正在从存储在我的 sd 卡中的视频创建缩略图,在网格视图中显示缩略图及其名称。在网格视图的 item selected 事件上弹出一个对话框并询问 x、y、right、bottom 位置,然后将其粘贴到 main 活动。我得到了视频文件,并尝试使用媒体存储创建缩略图,也将缩略图作为位图检索,但位图为空。在网格视图中显示视频名称,我可以选择相应的缩略图并且可以给出位置也可以将缩略图设置为主要活动。问题是位图为空且位图图像未显示(显示文本视频名称)。有什么问题 ?我想不通?请帮帮我?我的代码如下。提前致谢。

      if (f.isFile()) {
      if (fName.endsWith(".mpg")
    || fName.endsWith(".mov")
    || fName.endsWith(".wmv")
    || fName.endsWith(".rm")
    || fName.endsWith(".mp4")) {
    tv.setText(fName);
    path = f.getAbsolutePath();
    System.out.println("Video file path=>"+path);


 thumb = ThumbnailUtils.createVideoThumbnail(f.getAbsolutePath(),MediaStore.Video.Thumbnails.MICRO_KIND);


    if(thumb==null)
      {
         /**Every time it printing null**/
         System.out.println("Thumb is null");

      }
      iv.setImageBitmap(thumb);

【问题讨论】:

    标签: android


    【解决方案1】:

    来自ThumbnailUtils.createVideoThumbnail 文档:May return null if the video is corrupt or the format is not supported.

    默认情况下,几乎所有支持的格式都是 mp4 和 3gp。有关默认支持的媒体格式的完整列表,请参见此处:http://developer.android.com/guide/appendix/media-formats.html

    【讨论】:

    • 有没有办法从 .mov 文件中获取缩略图??比如说 wowza 服务器上的视频?
    • 但是在图库中我可以看到缩略图;-( 所以视频没有损坏或其他什么
    【解决方案2】:

    如果您从 sd 卡视频创建缩略图,这将创建 ThumbnailUtils.createVideoThumbnail,否则使用光标。

    See this example.

    【讨论】:

      【解决方案3】:
      Try this code. It is getting the thumbnail of videos from urls. instead of pass the path of sd card .it will help you . Dont forgot to add internet permission in manifest file.
      public class VideoThumbnailActivity extends Activity {
      
          public static final String Downloader = null;
          static String uri1="http://daily3gp.com/vids/lucky_guy.3gp";
          static String uri2="http://daily3gp.com/vids/reporter_hit_by_plane.3gp";
          static String uri3="http://daily3gp.com/vids/motorcycle_wipesout_explodes.3gp";
          static String uri4="http://commonsware.com/misc/test2.3gp";
          public static  String uri_array[]={uri1,uri2,uri3,uri4,uri1,uri2,uri3,uri4,uri1,uri2,uri3,uri4};
      
      
          ImageView imageView;
          String url;
          Gallery ga1,ga2;
      
          /** Called when the activity is first created. */
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
              imageView = (ImageView)findViewById(R.id.imageView);
              ga1 = (Gallery)findViewById(R.id.gallery1);
              ga1.setAdapter(new ImageAdapter(getApplicationContext()));
              imageView.setImageBitmap(ThumbnailUtils.createVideoThumbnail(uri_array[0], MediaStore.Video.Thumbnails.FULL_SCREEN_KIND));
      
              //on click event on gallery
              ga1.setOnItemClickListener(new OnItemClickListener() {
      
                  @Override
                  public void onItemClick(AdapterView<?> arg0, View view, final int position,long arg3) {
                   imageView.setImageBitmap(ThumbnailUtils.createVideoThumbnail(uri_array[position], MediaStore.Video.Thumbnails.FULL_SCREEN_KIND));
      
                   //on click event on imageview to play video
                   imageView.setOnClickListener(new OnClickListener() {
      
                                  @Override
                                  public void onClick(View view) {
                                      // TODO Auto-generated method stub
                                      Intent intent = new Intent(getApplicationContext(),PlayActivity.class);
                                      intent.putExtra("path",uri_array[position]);
                                      startActivity(intent);
                                  }
                              });
      
                              }
      
                      });
      
                  }
      
                  public class ImageAdapter extends BaseAdapter {
      
                      private Context ctx;
                      int imageBackground;
      
                      public ImageAdapter(Context c) {
                          ctx = c;
                          TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
                          imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
                          ta.recycle();
                      }
      
                      @Override
                      public int getCount() {
      
                          return uri_array.length;
      
                      }
      
                      @Override
                      public Object getItem(int arg0) {
      
                          return arg0;
                      }
      
                      @Override
                      public long getItemId(int arg0) {
      
                          return arg0;
                      }
      
                      @Override
                      public View getView(int position, View view, ViewGroup arg2) {
      
                          ImageView iv = new ImageView(ctx);
                          Bitmap curThumb = null;
                          curThumb = ThumbnailUtils.createVideoThumbnail(uri_array[position],MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);
                          iv.setImageBitmap(curThumb);
                          iv.setScaleType(ImageView.ScaleType.FIT_XY);
                          iv.setLayoutParams(new Gallery.LayoutParams(150,120));
                          iv.setBackgroundResource(imageBackground);
                          return iv;
                  }
              }
      

      让我知道您的问题是否已解决。

      【讨论】:

      • 检查下面的答案链接以获取来自 sd 卡的缩略图
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-01
      • 1970-01-01
      • 2013-06-15
      • 2023-04-05
      • 2010-12-13
      • 2012-02-23
      • 2018-12-21
      相关资源
      最近更新 更多