Example usage for android.media ThumbnailUtils createVideoThumbnail

List of usage examples for android.media ThumbnailUtils createVideoThumbnail

Introduction

In this page you can find the example usage for android.media ThumbnailUtils createVideoThumbnail.

Prototype

public static Bitmap createVideoThumbnail(String filePath, int kind) 

Source Link

Document

Create a video thumbnail for a video.

Usage

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static Bitmap entityToBitmap(Context context, HttpEntity entity, final String contentId,
        boolean withProgressBar, Long contentSize) {
    try {/*from   www  .  ja v  a  2  s.c  om*/
        File file = new File(getDir(), contentId);
        file.createNewFile();
        InputStream is = entity.getContent();

        /*
         * Read bytes to the Buffer until there is nothing more to read(-1)
         * and write on the fly in the file.
         */
        final FileOutputStream fos = new FileOutputStream(file);
        final int BUFFER_SIZE = 23 * 1024;
        BufferedInputStream bis = new BufferedInputStream(is, BUFFER_SIZE);
        byte[] baf = new byte[BUFFER_SIZE];
        int actual = 0;
        long total = 0;
        int totalpercent = 0;
        int auxtotal = 0;

        while (actual != -1) {
            fos.write(baf, 0, actual);
            actual = bis.read(baf, 0, BUFFER_SIZE);

            if (withProgressBar) {
                try {
                    total = total + actual;
                    auxtotal = (int) (((total * 100) / contentSize)) / 10;
                    if ((totalpercent != auxtotal) && (totalpercent != 10)) {
                        totalpercent = auxtotal;
                        Intent intent = new Intent();
                        intent.setAction(ConstantKeys.BROADCAST_DIALOG_PROGRESSBAR);
                        intent.putExtra(ConstantKeys.TOTAL, totalpercent * 10);
                        intent.putExtra(ConstantKeys.LOCALID,
                                contentId.replace(ConstantKeys.EXTENSION_3GP, ConstantKeys.STRING_DEFAULT)
                                        .replace(ConstantKeys.EXTENSION_JPG, ConstantKeys.STRING_DEFAULT));
                        context.sendBroadcast(intent);
                    }
                } catch (Exception e) {
                    log.error("Error tryng to send broadcast to progressbar", e);
                }
            }
        }

        fos.close();

        if (contentId.contains(ConstantKeys.EXTENSION_JPG)) {
            return decodeSampledBitmapFromPath(file.getAbsolutePath(), 200, 200);
        } else {
            return ThumbnailUtils.createVideoThumbnail(file.getAbsolutePath(),
                    MediaStore.Images.Thumbnails.MINI_KIND);
        }

    } catch (Exception e) {
        new File(getDir(), contentId).delete();
        return null;
    }
}

From source file:cn.iterlog.imgaepicker.home.MainFragment.java

@Override
public void showChooseImage(boolean isVideo, Uri uri) {
    if (!isVideo) {
        chooseIv.setImageURI(uri);/*from   w  w  w  .j av  a  2  s.c o m*/
    } else {
        Bitmap bm = ThumbnailUtils.createVideoThumbnail(uri.getPath(), MediaStore.Images.Thumbnails.MINI_KIND);
        chooseIv.setImageBitmap(bm);
    }
}

From source file:com.lovejoy777sarootool.rootool.preview.IconPreview.java

private static Bitmap getPreview(File file) {
    final boolean isImage = MimeTypes.isPicture(file);
    final boolean isVideo = MimeTypes.isVideo(file);
    final boolean isApk = file.getName().endsWith(".apk");
    Bitmap mBitmap = null;// www .j ava2s.  co m
    String path = file.getAbsolutePath();

    if (isImage) {
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        BitmapFactory.decodeFile(path, o);
        o.inJustDecodeBounds = false;

        if (o.outWidth != -1 && o.outHeight != -1) {
            final int originalSize = (o.outHeight > o.outWidth) ? o.outWidth : o.outHeight;
            o.inSampleSize = originalSize / mWidth;
        }

        mBitmap = BitmapFactory.decodeFile(path, o);

        cache.put(path, mBitmap);
        return mBitmap;
    } else if (isVideo) {
        mBitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MICRO_KIND);

        cache.put(path, mBitmap);
        return mBitmap;
    } else if (isApk) {
        final PackageInfo packageInfo = pm.getPackageArchiveInfo(path, PackageManager.GET_ACTIVITIES);

        if (packageInfo != null) {
            final ApplicationInfo appInfo = packageInfo.applicationInfo;

            if (appInfo != null) {
                appInfo.sourceDir = path;
                appInfo.publicSourceDir = path;
                final Drawable icon = appInfo.loadIcon(pm);

                if (icon != null) {
                    mBitmap = ((BitmapDrawable) icon).getBitmap();
                }
            }
        } else {
            // load apk icon from /res/drawable/..
            mBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.type_apk);
        }

        cache.put(path, mBitmap);
        return mBitmap;
    }
    return null;
}

From source file:com.ducnd.recordvideo_sample.CaptureDemoFragment.java

private Bitmap getThumbnail() {
    if (filename == null)
        return null;
    return ThumbnailUtils.createVideoThumbnail(filename, Thumbnails.FULL_SCREEN_KIND);
}

From source file:com.eeshana.icstories.activities.UploadVideoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // this will copy the license file and the demo video file.
    // to the videokit work folder location.
    // without the license file the library will not work.
    //copyLicenseAndDemoFilesFromAssetsToSDIfNeeded();
    setContentView(R.layout.upload_video_activity);

    height = SignInActivity.getScreenHeight(UploadVideoActivity.this);
    width = SignInActivity.getScreenWidth(UploadVideoActivity.this);
    mProgressDialog = new ProgressDialog(UploadVideoActivity.this);
    pDialog = new ProgressDialog(UploadVideoActivity.this);
    showCustomToast = new ShowCustomToast();
    connectionDetector = new ConnectionDetector(UploadVideoActivity.this);
    //      mProgressDialog=new ProgressDialog(UploadVideoActivity.this,AlertDialog.THEME_HOLO_LIGHT);
    //      mProgressDialog.setFeatureDrawableResource(height,R.drawable.rounded_toast);
    prefs = getSharedPreferences("PREF", MODE_PRIVATE);
    regId = prefs.getString("regid", "NA");
    SharedPreferences pref = getSharedPreferences("DB", 0);
    userid = pref.getString("userid", "1");
    SharedPreferences assign_prefs = getSharedPreferences("ASSIGN", 0);
    assignment_id = assign_prefs.getString("ASSIGN_ID", "");
    videoPath = getIntent().getStringExtra("VIDEOPATH");

    //      iCTextView=(TextView) findViewById(R.id.tvIC);
    //      iCTextView.setTypeface(CaptureVideoActivity.ic_typeface,Typeface.BOLD);
    //      storiesTextView=(TextView) findViewById(R.id.tvStories);
    //      storiesTextView.setTypeface(CaptureVideoActivity.stories_typeface,Typeface.BOLD);
    //      watsStoryTextView=(TextView) findViewById(R.id.tvWhatsStory);
    //      watsStoryTextView.setTypeface(CaptureVideoActivity.stories_typeface,Typeface.ITALIC);

    //      logoImageView=(ImageView) findViewById(R.id.ivLogo);
    //      RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams((int) (width/1.9), (int) (height/9.5));
    //      lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
    //      lp.setMargins(0, 0, 0, 0);
    //      logoImageView.setLayoutParams(lp);

    uploadtTextView = (TextView) findViewById(R.id.tvUpload);
    uploadtTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    //      extension=getIntent().getStringExtra("EXTENSION");
    //      folderPath = Environment.getExternalStorageDirectory().getPath()+"/ICStoriesFolder";
    //      if (!FileUtils.checkIfFolderExists(folderPath)) {
    //         boolean isFolderCreated = FileUtils.createFolder(folderPath);
    //         Log.i(Prefs.TAG, folderPath + " created? " + isFolderCreated);
    //         if (isFolderCreated) {
    ///*  w  w w  .j  a v  a 2s.  c o  m*/
    //         }
    //      }
    //command for rotating video 90 degree
    //String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -vf transpose=1 -s 160x120 -r 30 -aspect 4:3 -ab 48000 -ac 2 -ar 22050 -b 2097k "+folderPath+"/out."+extension;

    //Change Video Resolution:
    //String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -vf transpose=3 -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 "+folderPath+"/res."+extension;

    //command for compressing video 
    //      String commandStr="ffmpeg -y -i "+videoPath+" -strict experimental -s 320x240 -r 15 -aspect 3:4 -ab 12288 -vcodec mpeg4 -b 2097152 -sample_fmt s16 "+folderPath+"/test."+extension;
    //      setCommand(commandStr);
    //      runTranscoing();

    thumb = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.MINI_KIND);
    System.out.println("THUMB IMG  in uplaod== " + thumb);

    titleEditText = (EditText) findViewById(R.id.etTitle);
    titleEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    descriptionEditText = (EditText) findViewById(R.id.etDescripton);
    descriptionEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    locationEditText = (EditText) findViewById(R.id.etLocation);
    locationEditText.setTypeface(CaptureVideoActivity.stories_typeface);
    isAssignmentButton = (Button) findViewById(R.id.buttonCheck);
    isAssignmentButton.setTypeface(CaptureVideoActivity.stories_typeface);
    isAssignmentButton.setOnClickListener(this);
    dailyAssignTextView = (TextView) findViewById(R.id.tvDailyAssignment);
    dailyAssignTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    uploadButton = (Button) findViewById(R.id.buttonUpload);
    uploadButton.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout uploadRelativeLayout = (RelativeLayout) findViewById(R.id.rlUpload);
    RelativeLayout.LayoutParams lp9 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, height / 17);
    lp9.addRule(RelativeLayout.BELOW, R.id.rlDailyAssignment);
    lp9.setMargins(width / 7, 30, width / 7, 0);
    uploadRelativeLayout.setLayoutParams(lp9);
    uploadButton.setOnClickListener(this);

    //bottom bar

    homeRelativeLayout = (RelativeLayout) findViewById(R.id.rlHome);
    homeRelativeLayout.setBackgroundResource(R.drawable.press_border);
    homeRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    homeTextView = (TextView) homeRelativeLayout.findViewById(R.id.tvHome);
    homeTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    homeTextView.setTextColor(Color.parseColor("#fffffe"));
    RelativeLayout.LayoutParams lp4 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp4.addRule(RelativeLayout.ALIGN_LEFT);
    homeRelativeLayout.setLayoutParams(lp4);
    homeRelativeLayout.setOnClickListener(this);

    wallRelativeLayout = (RelativeLayout) findViewById(R.id.rlWall);
    wallRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    wallTextView = (TextView) wallRelativeLayout.findViewById(R.id.tvWall);
    wallTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout.LayoutParams lp5 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp5.addRule(RelativeLayout.RIGHT_OF, R.id.rlHome);
    wallRelativeLayout.setLayoutParams(lp5);
    wallRelativeLayout.setOnClickListener(this);

    settingsRelativeLayout = (RelativeLayout) findViewById(R.id.rlSettings);
    settingsRelativeLayout.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
    settingsTextView = (TextView) settingsRelativeLayout.findViewById(R.id.tvSettings);
    settingsTextView.setTypeface(CaptureVideoActivity.stories_typeface, Typeface.BOLD);
    RelativeLayout.LayoutParams lp6 = new RelativeLayout.LayoutParams(width / 3, width / 5);
    lp6.addRule(RelativeLayout.RIGHT_OF, R.id.rlWall);
    settingsRelativeLayout.setLayoutParams(lp6);
    settingsRelativeLayout.setOnClickListener(this);

    // current location
    locationDialog = new Dialog(UploadVideoActivity.this);
    locationDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    locationDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    locationDialog.setContentView(R.layout.location_dialog);
    locationDialog.setCancelable(true);
    LinearLayout dialogLayout = (LinearLayout) locationDialog.findViewById(R.id.ll1);
    okButton = (Button) dialogLayout.findViewById(R.id.OkBtn);
    okButton.setOnClickListener(this);
    cancelButton = (Button) dialogLayout.findViewById(R.id.cancelBtn);
    cancelButton.setOnClickListener(this);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    boolean network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (network_enabled) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
    } else {
        showCustomToast.showToast(UploadVideoActivity.this,
                "Could not find current location. Please enable location services of your device.");
    }
    //      else if(gps_enabled == false){
    //         locationDialog.show();
    //      }
}

From source file:com.amaze.carbonfilemanager.ui.icons.IconHolder.java

private Bitmap getVideoDrawable(String path) throws OutOfMemoryError {

    try {/*from   ww  w .  j ava  2 s . c o  m*/
        Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
        return thumb;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.nostra13.universalimageloader.core.decode.ContentImageDecoder.java

private Bitmap makeVideoThumbnailFromMediaStore(String filePath) {
    if (TextUtils.isEmpty(filePath))
        return null;
    Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.MINI_KIND);
    if (thumbnail != null) {
        Log8.d(thumbnail.getWidth(), thumbnail.getHeight());
    }//from   w w w. j av  a 2 s  .c  o m
    return thumbnail;
}

From source file:com.itsherpa.andg.imageloader.ImageFetcher.java

private Bitmap processVideoThumb(Object data) {
    String path = ((VideoThumbRequest) data).getPath();
    return ThumbnailUtils.createVideoThumbnail(path, Thumbnails.MICRO_KIND);
}

From source file:ir.rasen.charsoo.controller.image_loader.core.download.BaseImageDownloader.java

@TargetApi(Build.VERSION_CODES.FROYO)
private InputStream getVideoThumbnailStream(String filePath) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(filePath,
                MediaStore.Images.Thumbnails.FULL_SCREEN_KIND);
        if (bitmap != null) {
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.PNG, 0, bos);
            return new ByteArrayInputStream(bos.toByteArray());
        }/*w  w  w .j a  va  2 s  .  c  o m*/
    }
    return null;
}

From source file:com.rokolabs.app.common.image.ImageFetcher.java

/**
 * The main process method, which will be called by the ImageWorker in the
 * AsyncTask background thread./*  w  ww .j  a  v  a 2 s  . c  o m*/
 * 
 * @param data
 *            The data to load the bitmap, in this case, a regular http URL
 * @return The downloaded and resized bitmap
 */
@Override
protected Bitmap processBitmap(ImageFetchTask data, int index) {
    if (Utils.DEBUG) {
        Log.d(TAG, "processBitmap - " + data.getImageUrl(index));
    }
    File temp = null;
    Bitmap bmp = null;
    boolean diskCache = true;
    try {
        String url = data.getImageUrl(index);
        Logger.d("image url: " + url);
        Uri uri = Uri.parse(url);
        if ("file".equalsIgnoreCase(uri.getScheme())) {
            Logger.d("encoded path: " + uri.getEncodedPath());
            diskCache = false;
            bmp = decodeSampledBitmapFromFile(uri.getEncodedPath(), data.getDesiredWidth(),
                    data.getDesiredHeight());
        } else if ("asset".equalsIgnoreCase(uri.getScheme())) {
            diskCache = false;
            String path = uri.getEncodedPath();
            if (path.startsWith("/"))
                path = path.substring(1);
            Logger.d("asset path: " + path);
            bmp = decodeSampledBitmapFromAsset(mResources.getAssets(), path, data.getDesiredWidth(),
                    data.getDesiredHeight());
        } else if ("content".equalsIgnoreCase(uri.getScheme())) {
            diskCache = false;
            Logger.d("content path: " + url);
            bmp = decodeSampledBitmapFromInputStream(mAppContext.getContentResolver().openInputStream(uri),
                    data.getDesiredWidth(), data.getDesiredHeight());
        } else if ("video".equals(uri.getScheme())) {
            Logger.d("encoded path: " + uri.getEncodedPath());
            bmp = ThumbnailUtils.createVideoThumbnail(uri.getEncodedPath(), Thumbnails.MINI_KIND);
        } else {
            Logger.d(tempDir.getAbsolutePath());
            if (mImageCache != null) {
                bmp = mImageCache.getBitmapFromDiskCache(data.getImageUrl(index), data.getDesiredWidth(),
                        data.getDesiredHeight());
            }
            if (bmp == null) {
                temp = File.createTempFile("img_" + Math.random(), ".jpg", tempDir);
                if (downloadUrlToStream(data.getImageUrl(index), new FileOutputStream(temp))) {
                    Logg.d(temp.getAbsolutePath() + ", size =" + temp.length());
                    bmp = decodeSampledBitmapFromFile(temp.getAbsolutePath(), data.getDesiredWidth(),
                            data.getDesiredHeight());
                    if (bmp != null && mImageCache != null
                            && data.getTaskCachePolicy() == CachePolicy.MEM_AND_DISK) {
                        mImageCache.saveBitmapToDisk(data.getImageUrl(index), temp);
                    } else {
                        if (temp.length() < 2 * 1024)
                            Logg.d("temp file: " + new String(IOUtils.toByteArray(new FileInputStream(temp))));
                        temp.delete();
                    }
                } else {
                    temp.delete();
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "processBitmap - " + e);
    } catch (OutOfMemoryError oom) {
        Logger.printMemory("OOM error " + data.getImageUrl(index));
    } finally {
        if (bmp != null && mImageCache != null && diskCache
                && data.getTaskCachePolicy() == CachePolicy.MEM_AND_DISK)
            mImageCache.saveBitmapToDisk(data.getStoreKey(index), bmp);
    }
    return bmp;
}