2012-11-09 15 views
6

मैं अपने एसडी कार्ड में संग्रहीत वीडियो से थंबनेल बना रहा हूं, थंबनेल और उसके नाम ग्रिड व्यू में प्रदर्शित कर रहा हूं। ग्रिड व्यू के आइटम चयनित ईवेंट पर एक संवाद पॉप अप करता है और एक्स, वाई, दाएं, नीचे की स्थिति पूछता है और फिर इसे मुख्य गतिविधि में चिपकाता है। मुझे वीडियो फाइलें मिलीं, और मीडिया स्टोर का उपयोग करके थंबनेल बनाने की कोशिश की, थंबनेल को बिटमैप के रूप में पुनः प्राप्त कर रहा हूं, लेकिन बिटमैप शून्य है। ग्रिड व्यू में वीडियो नाम दिखाए जाते हैं और मैं संबंधित थंबनेल का चयन करने में सक्षम हूं और पदों को भी मुख्य गतिविधि में थंबनेल सेट करने में सक्षम हूं। समस्या यह है कि बिटमैप शून्य है और बिटमैप छवि नहीं दिख रही है (टेक्स्ट वी वीडियो नाम दिखाया गया है)। समस्या क्या है ? मेरे द्वारा इसका निर्धारण नहीं किया जा सकता? कृपया मेरी मदद करो? मेरा कोड नीचे दिया गया है। अग्रिम में धन्यवाद।वीडियो थंबनेल वापसी शून्य

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

उत्तर

3

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

+0

क्या .mov फ़ाइलों से थंबनेल प्राप्त करने का कोई तरीका है? उदाहरण के लिए Wowza सर्वर पर एक वीडियो कहें? –

+0

लेकिन गैलरी में मैं थंबनेल देख सकता हूं; - (तो वीडियो दूषित नहीं है या जो भी हो –

-1
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; 
      } 
     } 

मुझे पता है तुम्हारी समस्या है या नहीं हल हो गई है करते हैं।

+0

मैं sdcard से थंबनेल चाहते .. वैसे भी मुझे जाँच करें ... – Sunny

+0

जांच एसडी कार्ड से thumnails के लिए नीचे दिए गए जवाब लिंक –

+0

ठीक मुझे जाँच करें .. – Sunny

1

यदि आप एसडी कार्ड वीडियो से थंबनेल बना रहे हैं तो यह ThumbnailUtils.createVideoThumbnail बना देगा अन्यथा कर्सर का उपयोग करेगा।

See this example

संबंधित मुद्दे