@Test public void testLocalVideoMiniThumbnailSuccess() throws Exception { when(mImageRequest.getPreferredWidth()).thenReturn(100); when(mImageRequest.getPreferredHeight()).thenReturn(100); when(android.media.ThumbnailUtils.createVideoThumbnail( mFile.getPath(), MediaStore.Images.Thumbnails.MINI_KIND)) .thenReturn(mBitmap); doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mCloseableReference = ((CloseableReference) invocation.getArguments()[0]).clone(); return null; } }) .when(mConsumer) .onNewResult(any(CloseableReference.class), eq(true)); mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext); mExecutor.runUntilIdle(); assertEquals(1, mCloseableReference.getUnderlyingReferenceTestOnly().getRefCountTestOnly()); assertEquals( mBitmap, mCloseableReference.getUnderlyingReferenceTestOnly().get().getUnderlyingBitmap()); verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME); verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, null); }
private void createThumbnail(ContentValues map) throws IOException { File videoFile = fileFromResourceMap(map); Log.d("Creating thumbnail from video file " + videoFile.toString()); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail( videoFile.toString(), MediaStore.Video.Thumbnails.MINI_KIND); if (bitmap == null) { Log.w("Error creating thumbnail"); return; } String filename = (String) map.get(Resources.FILENAME); if (TextUtils.isEmpty(filename)) { throw new IOException("Must specify FILENAME when inserting Resource"); } Uri thumbnailUri = Resources.buildThumbnailUri(filename + THUMBNAIL_EXT); OutputStream ostream; try { ostream = getContext().getContentResolver().openOutputStream(thumbnailUri); } catch (FileNotFoundException e) { Log.d("Could not open output stream for thumbnail storage: " + e.getLocalizedMessage()); return; } bitmap.compress(Bitmap.CompressFormat.JPEG, 100, ostream); ostream.flush(); IOUtilities.closeStream(ostream); map.put(Resources.THUMBNAIL, thumbnailUri.toString()); }
@Test public void testLocalVideoMicroThumbnailSuccess() throws Exception { when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true); when(android.media.ThumbnailUtils.createVideoThumbnail( mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND)) .thenReturn(mBitmap); doAnswer( new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { mCloseableReference = ((CloseableReference) invocation.getArguments()[0]).clone(); return null; } }) .when(mConsumer) .onNewResult(any(CloseableReference.class), eq(true)); mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext); mExecutor.runUntilIdle(); assertEquals(1, mCloseableReference.getUnderlyingReferenceTestOnly().getRefCountTestOnly()); assertEquals( mBitmap, mCloseableReference.getUnderlyingReferenceTestOnly().get().getUnderlyingBitmap()); verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME); Map<String, String> thumbnailFoundMap = ImmutableMap.of(LocalVideoThumbnailProducer.CREATED_THUMBNAIL, "true"); verify(mProducerListener) .onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, thumbnailFoundMap); }
private void setVideo() { Bitmap image = ThumbnailUtils.createVideoThumbnail(mData.filePath, Video.Thumbnails.MINI_KIND); if (image == null) { image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_missing_thumbnail_video); } mContactImage.setImageBitmap(image); mContactImage.setVisibility(View.VISIBLE); mContactImageLayout.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent mediaIntent = new Intent(Intent.ACTION_VIEW); Uri uri = Uri.parse(mData.filePath); String type = "video/*"; mediaIntent.setDataAndType(uri, type); mContext.startActivity(mediaIntent); } }); mContactImageParent.setOnCreateContextMenuListener(mRecipientsMenuCreateListener); }
private Bitmap getVideoBitmap(String path) { Bitmap bitmap; bitmap = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MICRO_KIND); bitmap = ThumbnailUtils.extractThumbnail(bitmap, 200, 200, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; }
public UFile(String path) { try { file = new File(path); this.path = file.getPath(); this.name = file.getName(); size = file.length(); thumbNail = null; if (isMovie()) { MediaMetadataRetriever retriever = new MediaMetadataRetriever(); retriever.setDataSource(path); String time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); movieLength = Long.parseLong(time); thumbNail = ThumbnailUtils.createVideoThumbnail( path, MediaStore.Video.Thumbnails.FULL_SCREEN_KIND); } else if (isImage()) { Bitmap temp = BitmapFactory.decodeFile(file.getPath()); float scale = context.getResources().getDisplayMetrics().densityDpi / 160f; thumbNail = ThumbnailUtils.extractThumbnail(temp, (int) (50f * scale), (int) (50f * scale)); } else if (file.isDirectory()) { thumbNail = BitmapFactory.decodeResource(null, R.mipmap.docu); } } catch (Exception e) { file = null; } }
/** * 获取视频缩略图 * * @param videoPath * @param width * @param height * @param kind * @return */ private Bitmap getVideoThumbnail(String videoPath, int width, int height, int kind) { Bitmap bitmap = null; bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind); bitmap = ThumbnailUtils.extractThumbnail( bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; }
/** * 获取缩略图 * * @param url * @param width * @param height * @return */ private Bitmap getVideoThumbnail(String videoPath, int width, int height) { Bitmap bitmap = null; // 获取视频的缩略图 bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, MediaStore.Images.Thumbnails.MICRO_KIND); bitmap = ThumbnailUtils.extractThumbnail( bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; }
@Test(expected = RuntimeException.class) public void testFetchLocalFileFailsByThrowing() throws Exception { when(android.media.ThumbnailUtils.createVideoThumbnail( mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND)) .thenThrow(mException); verify(mConsumer).onFailure(mException); verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME); verify(mProducerListener) .onProducerFinishWithFailure(mRequestId, PRODUCER_NAME, mException, null); }
private Bitmap getVideoDrawable(String path) throws OutOfMemoryError { try { Bitmap thumb = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND); return thumb; } catch (Exception e) { e.printStackTrace(); return null; } }
private void showUploadSuccessDialog() { // set up dialogVideoInfo dialogUploadSuccess.setCancelable(true); state = 0; ImageView iv_thumb = (ImageView) dialogUploadSuccess.findViewById(R.id.iv_thumb); LinearLayout ll_video_info = (LinearLayout) dialogUploadSuccess.findViewById(R.id.ll_upload_success); if (display.getWidth() > display.getHeight()) { ll_video_info.getLayoutParams().width = display.getHeight(); ll_video_info.getLayoutParams().height = (int) Math.round((float) display.getHeight() * 0.7); } else { ll_video_info.getLayoutParams().width = (int) Math.round((float) display.getWidth() * 0.7); ll_video_info.getLayoutParams().height = (int) Math.round((float) display.getHeight() * 0.6); iv_thumb.getLayoutParams().height = (int) Math.round((float) display.getHeight() * 0.6) / 2; } Bitmap bMap = ThumbnailUtils.createVideoThumbnail( Main.this.pathfromURI, MediaStore.Video.Thumbnails.MICRO_KIND); iv_thumb.setScaleType(ImageView.ScaleType.CENTER_CROP); iv_thumb.setImageBitmap(bMap); // set up button ImageView iv_close = (ImageView) dialogUploadSuccess.findViewById(R.id.iv_close); iv_close.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); finish(); getActivityMediator().showMain(); } }); Button btn_upload_successfully = (Button) dialogUploadSuccess.findViewById(R.id.btn_upload_successfully); btn_upload_successfully.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); finish(); getActivityMediator().showMain(); } }); // now that the dialogVideoInfo is set up, it's time to show it dialogUploadSuccess.show(); }
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { try { if (action.equals("createVideoThumbnail")) { String pvUrl = args.getString(0); if (pvUrl != null && pvUrl.length() > 0) { // do smth with pvUrl // MINI_KIND: 512 x 384 thumbnail Bitmap bmThumbnail = ThumbnailUtils.createVideoThumbnail(pvUrl, Thumbnails.MINI_KIND); try { FileOutputStream out = new FileOutputStream(pvUrl + ".jpg"); bmThumbnail.compress(Bitmap.CompressFormat.JPEG, 55, out); // File file = new File(pvUrl + ".jpg"); // boolean val = file.exists(); } catch (Exception e) { e.printStackTrace(); } callbackContext.success(pvUrl + ".jpg"); return true; } } else { if (action.equals("createImageThumbnail")) { String pvUrl = args.getString(0); if (pvUrl != null && pvUrl.length() > 0) { // do smth with pvUrl Bitmap bitmap = BitmapFactory.decodeFile(pvUrl); Bitmap bmThumbnail = ThumbnailUtils.extractThumbnail(bitmap, 512, 384); try { FileOutputStream out = new FileOutputStream(pvUrl + ".jpg"); bmThumbnail.compress(Bitmap.CompressFormat.JPEG, 55, out); } catch (Exception e) { e.printStackTrace(); } callbackContext.success(pvUrl + ".jpg"); return true; } } } } catch (JSONException e) { } return false; }
@Test public void testLocalVideoMicroThumbnailReturnsNull() throws Exception { when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true); when(android.media.ThumbnailUtils.createVideoThumbnail( mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND)) .thenReturn(null); mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext); mExecutor.runUntilIdle(); verify(mConsumer).onNewResult(null, true); verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME); Map<String, String> thumbnailNotFoundMap = ImmutableMap.of(LocalVideoThumbnailProducer.CREATED_THUMBNAIL, "false"); verify(mProducerListener) .onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, thumbnailNotFoundMap); }
public View getView(int position, View view, ViewGroup viewGroup) { if (view == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); view = inflater.inflate(resource, viewGroup, false); } Lampiran lampiran = listOfLampiran.get(position); ImageView imageLampiran = (ImageView) view.findViewById(R.id.ImageViewLampiran); TextView textViewCaption = (TextView) view.findViewById(R.id.TextViewCaption); String fileNamaLampiran = lampiran .getImage() .substring(lampiran.getImage().lastIndexOf(".") + 1, lampiran.getImage().length()); if (fileNamaLampiran.equals("jpg") || fileNamaLampiran.equals("png") || fileNamaLampiran.equals("gif")) { try { imageLampiran.setImageBitmap( GlobalFunction.decodeSampledBitmapFromFile(lampiran.getImage(), 50, 50)); } catch (FileNotFoundException e) { e.printStackTrace(); } } else if (fileNamaLampiran.equals("avi") || fileNamaLampiran.equals("mp4") || fileNamaLampiran.equals("flv") || fileNamaLampiran.equals("mkv") || fileNamaLampiran.equals("3gp")) { Bitmap fileLampiran = ThumbnailUtils.createVideoThumbnail( lampiran.getImage(), MediaStore.Images.Thumbnails.MINI_KIND); imageLampiran.setImageBitmap(fileLampiran); } else { Toast.makeText( context, "Maaf Format Lampiran Yang Anda Pilih Tidak Sesuai", Toast.LENGTH_SHORT) .show(); } textViewCaption.setText(lampiran.getJudul()); return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = new ImageView(mGridView.getContext()); imageView.setLayoutParams(new GridView.LayoutParams(120, 120)); } else { imageView = (ImageView) convertView; } Cursor c = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null, null, null); c.moveToPosition(position); int dataIndex = c.getColumnIndex(MediaStore.Video.Media.DATA); String path = c.getString(dataIndex); Bitmap bmp = ThumbnailUtils.createVideoThumbnail(path, MediaStore.Video.Thumbnails.MINI_KIND); imageView.setImageBitmap(bmp); return (View) imageView; }
public static Bitmap getVideoThumbnail(String filePath, int maxSize) { Bitmap bmp = ThumbnailUtils.createVideoThumbnail(filePath, Images.Thumbnails.MINI_KIND); if (bmp != null) { final int width = bmp.getWidth(); final int height = bmp.getHeight(); if (width > maxSize || height > maxSize) { int fixWidth = 0; int fixHeight = 0; if (height > width) { fixHeight = maxSize; fixWidth = width * fixHeight / height; } else { fixWidth = maxSize; fixHeight = height * fixWidth / width; } bmp = Bitmap.createScaledBitmap(bmp, fixWidth, fixHeight, false); } } return bmp; }
public View getView(String path, Boolean editMode, final Context C) { ImageView button = new ImageView(C); final String videoPath = path + content; button.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(C, VideoPlayerActivity.class); intent.putExtra("VIDEO_PATH", videoPath); C.startActivity(intent); } }); Drawable[] layers = new Drawable[2]; layers[0] = new BitmapDrawable( C.getResources(), ThumbnailUtils.createVideoThumbnail(videoPath, Thumbnails.MINI_KIND)); layers[1] = (C.getResources().getDrawable(R.drawable.ic_action_play)); LayerDrawable ld = new LayerDrawable(layers); ld.setLayerInset(1, 40, 0, 40, 0); ((BitmapDrawable) ld.getDrawable(1)).setGravity(Gravity.CENTER); button.setImageDrawable(ld); return button; }
@Override protected void onResume() { super.onResume(); // File [] filelist = new File[cnt]; Log.d("JWJWJW", "onResume"); array.clear(); for (int i = 0; i < cnt; i++) { // filelist[i] = new File(promisedPath+i+".mp4"); Log.d("JWJWJW", promisedPath + i + ".mp4"); if (new File(promisedPath + i + ".mp4").exists()) { array.add(promisedPath + i + ".mp4"); Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(promisedPath + i + ".mp4", Thumbnails.MICRO_KIND); thumbnailArray.get(i).setImageBitmap(thumbnail); thumbnailArray.get(i).setColorFilter(0x00000000, Mode.SRC_OVER); } } int idx = mediaPref.getCurrentIdx(); thumbnailArray.get(idx).setColorFilter(0xaaffd700, Mode.SRC_OVER); setSceneNo(idx); }
public static Bitmap loadImageFromFilePath(String filePath) { return ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND); }
private void showVideoInfoDialog(final String pathFromUri) { dialogUpload.cancel(); // set up dialogVideoInfo switch (orientation) { case Configuration.ORIENTATION_PORTRAIT: case Configuration.ORIENTATION_UNDEFINED: case Configuration.ORIENTATION_SQUARE: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); break; case Configuration.ORIENTATION_LANDSCAPE: setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); break; default: break; } new DownloadListCatigoriesTask().execute(); dialogVideoInfo.setCancelable(true); ImageView iv_thumb = (ImageView) dialogVideoInfo.findViewById(R.id.iv_thumb); LinearLayout ll_video_info = (LinearLayout) dialogVideoInfo.findViewById(R.id.ll_video_info); if (display.getWidth() > display.getHeight()) { ll_video_info.getLayoutParams().width = display.getHeight(); ll_video_info.getLayoutParams().height = (int) Math.round((float) display.getHeight() * 0.75); } else { ll_video_info.getLayoutParams().width = (int) Math.round((float) display.getWidth() * 0.7); ll_video_info.getLayoutParams().height = (int) Math.round((float) display.getHeight() * 0.73); iv_thumb.getLayoutParams().height = (int) Math.round((float) display.getHeight() * 0.5) / 2; } Bitmap bMap = ThumbnailUtils.createVideoThumbnail(pathFromUri, MediaStore.Video.Thumbnails.MICRO_KIND); iv_thumb.setScaleType(ImageView.ScaleType.CENTER_CROP); iv_thumb.setImageBitmap(bMap); pb_uploading = (ProgressBar) dialogVideoInfo.findViewById(R.id.pb_uploading); tv_uploading = (TextView) dialogVideoInfo.findViewById(R.id.tv_uploading); final EditText et_title = (EditText) dialogVideoInfo.findViewById(R.id.et_title); final EditText et_description = (EditText) dialogVideoInfo.findViewById(R.id.et_description); final EditText et_tags = (EditText) dialogVideoInfo.findViewById(R.id.et_tags); uploadToken = new UploadToken(TAG, 5); // set up button ImageView iv_close = (ImageView) dialogVideoInfo.findViewById(R.id.iv_close); rl_upload = (RelativeLayout) dialogVideoInfo.findViewById(R.id.rl_upload); rl_upload.setVisibility(View.VISIBLE); pb_uploading.setVisibility(View.GONE); tv_uploading.setVisibility(View.GONE); iv_close.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); rl_upload.setVisibility(View.VISIBLE); pb_uploading.setVisibility(View.GONE); tv_uploading.setVisibility(View.GONE); dialogVideoInfo.cancel(); uploadToken.setStartUpload(false); Log.w(TAG, "close video info dialog"); } }); rl_upload.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { rl_upload.setVisibility(View.GONE); pb_uploading.setVisibility(View.VISIBLE); tv_uploading.setVisibility(View.VISIBLE); if (spinner != null) { Main.this.pathfromURI = pathFromUri; Main.this.category = spinner.getSelectedItem().toString(); Main.this.title = et_title.getText().toString(); Main.this.description = et_description.getText().toString(); Main.this.tags = et_tags.getText().toString(); uploadToken.setStartUpload(true); new UploadDataTask().execute(); } } }); dialogVideoInfo.show(); }
@Override protected Bitmap processBitmap(Object data) { String filePath = String.valueOf(data); return ThumbnailUtils.createVideoThumbnail(filePath, Thumbnails.MICRO_KIND); }
@SuppressWarnings("unused") @Override protected String doInBackground(Void... unsued) { MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(fileuri, MediaStore.Images.Thumbnails.MINI_KIND); InputStream is; BitmapFactory.Options bfo; Bitmap bitmapOrg; ByteArrayOutputStream bao; bfo = new BitmapFactory.Options(); bfo.inSampleSize = 2; /*bitmapOrg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + customImage, bfo);*/ bao = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bao); byte[] ba = bao.toByteArray(); String ba1 = Base64.encodeToString(ba, Base64.DEFAULT); is = new ByteArrayInputStream(bao.toByteArray()); /*reqEntity.addPart("myFile", deviceId+ ".jpg", is);*/ // File sourceFile = new File(fileuri); reqEntity.addPart("myFile", deviceId + ".jpg", is); // Adding file data to http body // reqEntity.addPart("thumb", new FileBody(sourceFile)); String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString(); try { reqEntity.addPart("basepath", new StringBody(base)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { reqEntity.addPart("localfilepath", new StringBody(fileuri)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { reqEntity.addPart("name", new StringBody(deviceId)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } // FileBody bin = new FileBody(new File("C:/ABC.txt")); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new // Here you need to put your server file address HttpPost("http://torqkd.com/user/ajs/uploadvideo"); // httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httppost.setEntity(reqEntity); HttpResponse response = httpclient.execute(httppost); // HttpEntity entity = response.getEntity(); // is = entity.getContent(); Context context = allfilelist.this; Intent cameraintent = new Intent(context, MainActivity.class); cameraintent.putExtra("vlocalfileuril", fileuri); // Launch default browser context.startActivity(cameraintent); Log.v("log_tag", "In the try Loop"); } catch (Exception e) { Log.v("log_tag", "Error in http connection " + e.toString()); } return "Success"; // (null); }
private Bitmap getThumbnail() { if (filename == null) return null; return ThumbnailUtils.createVideoThumbnail(filename, Thumbnails.FULL_SCREEN_KIND); }
// TODO this is heavy operation (hence asynctask), we should cache thumbnails and store so we // dont need to run this every single time @Override protected Bitmap doInBackground(File... params) { return ThumbnailUtils.createVideoThumbnail( params[0].toString(), MediaStore.Images.Thumbnails.MINI_KIND); }
@SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.avideo); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (!BuildVars.debug) { getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); } } NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancelAll(); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); title = (TextView) findViewById(R.id.tvVtitle); reports = new Reports(getApplicationContext(), "Training"); mtitle = (TextView) findViewById(R.id.mtitle); icon = (ImageView) findViewById(R.id.miconimage); detail = (TextView) findViewById(R.id.tvVDetail); from = (TextView) findViewById(R.id.tvVFrom); summary = (TextView) findViewById(R.id.tvVsummary); vfullscreenplay = (ImageView) findViewById(R.id.vfullscreenplay); vid = (com.sanofi.in.mobcast.CustomVideoView) findViewById(R.id.vvType); mtitle.setText("Training"); icon.setImageResource(R.drawable.training); // share = (Button) findViewById(R.id.bVshare); vid.setOnPreparedListener(this); btn = (ImageView) findViewById(R.id.vbackground); play = (ImageView) findViewById(R.id.vbackgroundplay); play.setOnClickListener(BackgroundclkListener); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { play.setAlpha(0.7f); } btn.setOnClickListener(BackgroundclkListener); share = (Button) findViewById(R.id.iv6); onNewIntent(getIntent()); share.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) { if (android.os.Build.VERSION.SDK_INT >= 11) { v.setAlpha(0.5f); } // v.getBackground().setAlpha(45); } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) { if (android.os.Build.VERSION.SDK_INT >= 11) { v.setAlpha(1); } // v.getBackground().setAlpha(255); } return false; } }); vfullscreenplay.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub // isToRate = true; vid.pause(); time = vid.getCurrentPosition(); Log.d("Paused at ", "" + time); Intent i = new Intent(TrainingVideo.this, VideoFullscreen.class); i.putExtra("name", name); Log.d("name", name); i.putExtra("StartAt", (int) time); onDestroy(); startActivity(i); } }); detail.setText(DateUtils.formatDate(Ddetail)); share.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub reports.updateShare(aid); final Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("video/mp4"); String shareBody = title.getText() + "\n" + from.getText() + "\n ON: " + detail.getText() + "\n" + summary.getText(); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title.getText()); prefs.edit().putInt("StartAt", vid.getCurrentPosition()).commit(); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(file)); startActivity(Intent.createChooser(shareIntent, "Share video")); } }); String roo1t = Environment.getExternalStorageDirectory().toString() + Constants.APP_FOLDER_VIDEO + name; Bitmap thumbnail = ThumbnailUtils.createVideoThumbnail(roo1t, MediaStore.Images.Thumbnails.MINI_KIND); BitmapDrawable bitmapDrawable = new BitmapDrawable(thumbnail); vid.setBackgroundDrawable(bitmapDrawable); // btn.setBackgroundDrawable(bitmapDrawable); btn.setImageDrawable(bitmapDrawable); vid.setVideoPath(roo1t); mc = new MediaController(this); mc.show(500000); mc.setAnchorView(vid); vid.setMediaController(mc); vid.requestFocus(); // vid.setPlayPauseListener(ppl); }
@SuppressLint("NewApi") public void onActivityResult(int requestCode, int resultCode, Intent data) { selectedVideos = new ArrayList<String>(); if (resultCode == RESULT_OK && requestCode == VIDEO_RESULT) { try { uriVideo = data.getData(); /*Toast.makeText(createvideo.this, uriVideo.getPath(), Toast.LENGTH_LONG).show();*/ selectedImagePath = uriVideo.getPath(); // selectedImages = new ArrayList<String>(); byte[] ba = getCapturedVideoStream(editvideo.this, data); MyWrite(ba); // selectedImagePath = Base64.encodeBytes(ba); selectedVideos.add(selectedImagePath); /*Toast.makeText(createvideo.this, selectedImagePath, Toast.LENGTH_LONG).show();*/ Bitmap thumb = ThumbnailUtils.createVideoThumbnail( selectedImagePath, MediaStore.Images.Thumbnails.MICRO_KIND); /* * Drawable d = new BitmapDrawable(getResources(),thumb); * //video_intro.setBackgroundDrawable(d); //int height = * img_videointro.getHeight(); //int width = * img_videointro.getWidth(); * img_videointro.setImageBitmap(thumb); d = * getResources().getDrawable(R.drawable.videowith); * img_videointro.setBackgroundDrawable(d); * img_videointro.setPadding(0,10,0,0); */ // img_videointro.getLayoutParams().height = height; // img_videointro.getLayoutParams().width = width; // LinearLayout.LayoutParams layoutParams = new // LinearLayout.LayoutParams(video_intro.getWidth()-10, // video_intro.getHeight()-10); // video_intro.setLayoutParams(layoutParams); // video_intro.setText(""); int height = img_videointro.getHeight(); int width = img_videointro.getWidth(); if (detectVideo.equals("1")) { uploadVideo(c.link.toString() + "/video1.php", "video1"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videointro.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videointro.setBackgroundDrawable(d); img_videointro.setPadding(0, 10, 0, 0); img_videointro.setMaxHeight(height); img_videointro.setMaxWidth(width); } else if (detectVideo.equals("2")) { uploadVideo(c.link.toString() + "/video2.php", "video2"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videopet.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videopet.setBackgroundDrawable(d); img_videopet.setPadding(0, 10, 0, 0); img_videopet.setMaxHeight(height); img_videopet.setMaxWidth(width); } else if (detectVideo.equals("3")) { uploadVideo(c.link.toString() + "/video3.php", "video3"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videoplace.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videoplace.setBackgroundDrawable(d); img_videoplace.setPadding(0, 10, 0, 0); img_videoplace.setMaxHeight(height); img_videoplace.setMaxWidth(width); } else if (detectVideo.equals("4")) { uploadVideo(c.link.toString() + "/video4.php", "video4"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videopick.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videopick.setBackgroundDrawable(d); img_videopick.setPadding(0, 10, 0, 0); img_videopick.setMaxHeight(height); img_videopick.setMaxWidth(width); } } catch (Exception e) { } } }
public void stopRecording(DeviceVideoControl.RecordingListener listener) { if (!this.recording && listener != null) { listener.onVideoFinishedRecording(false); waitPreviewTime(); return; } // Stop recording and release camera try { this.recorder.stop(); } catch (Exception ex) { Gdx.app.error(VIDEO_LOGTAG, "Stop failed! cleaning file", ex); this.recording = false; if (listener != null) { listener.onVideoFinishedRecording(false); } FileHandle corruptFile = Gdx.files.absolute(auxVideoPath + VIDEO_ID); if (corruptFile.exists()) { corruptFile.delete(); } waitPreviewTime(); return; } final String thumbPath = this.auxVideoPath; final String miniKindPath = thumbPath + VIDEO_THUMBNAIL_ID; OutputStream thumbnailFos = null; try { // MINI_KIND Thumbnail Bitmap bmMiniKind = ThumbnailUtils.createVideoThumbnail(this.auxVideoPath + VIDEO_ID, Thumbnails.MINI_KIND); if (bmMiniKind == null) { Gdx.app.error(VIDEO_LOGTAG, "Video corrupt or format not supported! (MINI_KIND)"); this.recording = false; if (listener != null) { listener.onVideoFinishedRecording(false); } waitPreviewTime(); return; } thumbnailFos = new FileOutputStream(new File(miniKindPath)); bmMiniKind.compress(Bitmap.CompressFormat.JPEG, 90, thumbnailFos); thumbnailFos.flush(); if (bmMiniKind != null) { bmMiniKind.recycle(); bmMiniKind = null; } if (listener != null) { listener.onVideoFinishedRecording(true); } Gdx.app.log(VIDEO_LOGTAG, "Recording stopped, video thumbnail saved!"); } catch (FileNotFoundException fnfex) { if (listener != null) { listener.onVideoFinishedRecording(false); } Gdx.app.error("Picture", "File not found creating the video thumbnail", fnfex); } catch (IOException ioex) { // Something went wrong creating the video thumbnail if (listener != null) { listener.onVideoFinishedRecording(false); } Gdx.app.error(VIDEO_LOGTAG, "Something went wrong creating the Video Thumbnail", ioex); } finally { close(thumbnailFos); } waitPreviewTime(); this.recording = false; }
public ArrayList<ImageItem> getFilePathsold() { // Uri u = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;; String[] projection = {MediaStore.Images.Thumbnails.DATA}; Cursor c = null; Context context; SortedSet<String> dirList = new TreeSet<>(); ArrayList<ImageItem> resultIAV = new ArrayList<>(); String[] directories = null; // if (u != null) { c = this.getContentResolver() .query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null); // } if ((c != null) && (c.moveToFirst())) { do { String tempDir = c.getString(0); tempDir = tempDir.substring(0, tempDir.lastIndexOf("/")); try { dirList.add(tempDir); } catch (Exception e) { } } while (c.moveToNext()); directories = new String[dirList.size()]; dirList.toArray(directories); } for (int i = 0; i < dirList.size(); i++) { File imageDir = new File(directories[i]); File[] imageList = imageDir.listFiles(); if (imageList == null) continue; for (File imagePath : imageList) { try { if (imagePath.isDirectory()) { imageList = imagePath.listFiles(); } if (imagePath.getName().contains(".jpg") || imagePath.getName().contains(".JPG") || imagePath.getName().contains(".jpeg") || imagePath.getName().contains(".JPEG") || imagePath.getName().contains(".png") || imagePath.getName().contains(".PNG") || imagePath.getName().contains(".gif") || imagePath.getName().contains(".GIF") || imagePath.getName().contains(".bmp") || imagePath.getName().contains(".BMP")) { String path = imagePath.getAbsolutePath(); /* Toast.makeText(getApplicationContext(), path, Toast.LENGTH_LONG).show();*/ Bitmap bitmap; bitmap = BitmapFactory.decodeFile(path); resultIAV.add(new ImageItem(bitmap, path)); } if (imagePath.getName().contains(".mp4") || imagePath.getName().contains(".MP4") || imagePath.getName().contains(".Mp4")) { String path = imagePath.getAbsolutePath(); Toast.makeText(getApplicationContext(), path, Toast.LENGTH_LONG).show(); bitmap = ThumbnailUtils.createVideoThumbnail(path, Thumbnails.FULL_SCREEN_KIND); ; resultIAV.add(new ImageItem(bitmap, path)); } } // } catch (Exception e) { e.printStackTrace(); } } } return resultIAV; }
private Bitmap getBitmap(String url) { File f = getFile(url); Bitmap bitmap; // from cache bitmap = decodeFile(f.toString()); if (bitmap != null) { return bitmap; } // from uri if (url.contains("content:")) { bitmap = decodeFile(url); return bitmap; } try { int res_id = Integer.parseInt(url); Bitmap b = decodeFile(url); return b; } catch (NumberFormatException ignored) { } // from video bitmap = null; bitmap = ThumbnailUtils.createVideoThumbnail(url, MediaStore.Video.Thumbnails.MINI_KIND); if (bitmap != null) { return bitmap; } // from downloaded File fi = new File(url); if (fi.exists()) { bitmap = null; bitmap = decodeFile(fi.toString()); return bitmap; } // from web try { bitmap = null; URL imageUrl = new URL(url); HttpURLConnection conn; conn = (HttpURLConnection) imageUrl.openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setInstanceFollowRedirects(true); InputStream is = conn.getInputStream(); OutputStream os = new FileOutputStream(f); CopyStream(is, os); os.close(); conn.disconnect(); bitmap = decodeFile(f.toString()); return bitmap; } catch (Throwable ex) { if (ex instanceof OutOfMemoryError) { memoryCache.clear(); } return null; } }
@Override protected Bitmap doInBackground(String... params) { return ThumbnailUtils.createVideoThumbnail( Storage.StoragePath + mFileList.get(position), Images.Thumbnails.MINI_KIND); }