Android Open Source - Chopping Media Utils






From Project

Back to project page Chopping.

License

The source code is released under:

Apache License

If you think the Android project Chopping listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.chopping.utils;
//from www.ja v a  2s  . c o  m
import com.chopping.application.LL;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.concurrent.TimeUnit;

import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;

/**
 * Utils for media usages.
 *
 * @author Xinyue Zhao
 */
public final class MediaUtils {
  /**
   * Asyn-post to get duration of video.
   *
   * @param _context
   *     {@link android.content.Context}.
   * @param _urlToVideo
   *     The url to video in {@link java.lang.String}.
   *
   * @return {@link java.lang.String}. The Duration of video in long format  like {@code 03:45}.
   * <p/>
   * Null might be returned if unsuccessful since some reasons like with offline status try to get a remote video.
   */
  public static String getVideoDuration(Context _context, String _urlToVideo) {
    String dur = null;
    try {
      MediaPlayer mp = MediaPlayer.create(_context, Uri.parse(_urlToVideo));
      int duration = mp.getDuration();
      mp.release();
      /*convert millis to appropriate time*/
      NumberFormat f = new DecimalFormat("##00");
      dur = String.format("%s:%s",
          f.format(TimeUnit.MILLISECONDS.toMinutes(duration)),
          f.format(TimeUnit.MILLISECONDS.toSeconds(duration) -
              TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration))));
    } catch (Exception _e) {
      LL.e("Can't get duration of video, checkout internet connection.");
    }
    return dur;
  }
}




Java Source Code List

com.android.internal.telephony.ITelephony.java
com.chopping.ApplicationTest.java
com.chopping.activities.BaseActivity.java
com.chopping.activities.BrightnessRefreshActivity.java
com.chopping.activities.ErrorHandlerActivity.java
com.chopping.application.BasicPrefs.java
com.chopping.application.ErrorHandler.java
com.chopping.application.IApp.java
com.chopping.application.InstalledAppReceiver.java
com.chopping.application.LL.java
com.chopping.bus.AirplaneModeOnEvent.java
com.chopping.bus.ApplicationConfigurationDownloadedEvent.java
com.chopping.bus.ApplicationConfigurationLoadingIgnoredEvent.java
com.chopping.bus.CloseDrawerEvent.java
com.chopping.bus.ExternalAppChangedEvent.java
com.chopping.bus.LinkToExternalAppEvent.java
com.chopping.bus.ReloadEvent.java
com.chopping.data.AppListItem.java
com.chopping.data.AppList.java
com.chopping.exceptions.CanNotOpenOrFindAppPropertiesException.java
com.chopping.exceptions.InvalidAppPropertiesException.java
com.chopping.exceptions.OperationFailException.java
com.chopping.fragments.AppListFragment.java
com.chopping.fragments.BaseFragment.java
com.chopping.fragments.ErrorHandlerFragment.java
com.chopping.net.GsonRequestTask.java
com.chopping.net.TaskHelper.java
com.chopping.utils.Consts.java
com.chopping.utils.DeviceUtils.java
com.chopping.utils.IncomingCallReceiver.java
com.chopping.utils.MediaUtils.java
com.chopping.utils.NetworkUtils.java
com.chopping.utils.Utils.java
com.chopping.utils.views.OneDirectionScrollView.java