Android Open Source - MediaCodecVideoPlayer Utils






From Project

Back to project page MediaCodecVideoPlayer.

License

The source code is released under:

Apache License

If you think the Android project MediaCodecVideoPlayer 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

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 */*  w  w  w  .  ja  va  2  s. c o m*/
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jasonsoft.mediacodecvideoplayer;

import android.content.Context;
import android.graphics.Bitmap;

import com.jasonsoft.mediacodecvideoplayer.cache.CacheManager;
import com.jasonsoft.mediacodecvideoplayer.data.AsyncDrawable;
import com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailParams;
import com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailResult;

public class Utils {

    /**
     * Instances should NOT be constructed in standard programming.
     */
    public Utils() {
        super();
    }

    /**
     * The number of ms in one second.
     */
    public static final long ONE_SECOND = 1000;

    /**
     * The number of ms in one minute.
     */
    public static final long ONE_MINUTE = 60 * ONE_SECOND;

    /**
     * The number of ms in an hour.
     */
    public static final long ONE_HOUR = 60 * ONE_MINUTE;

    /**
     * Returns a human-readable version of the file size, where the input
     * represents a specific number of bytes.
     *
     * @param size  the number of bytes
     * @return a human-readable display value (includes units)
     */
    public static String msToDisplayDuration(long ms) {
        if (ms / ONE_HOUR > 0) {
            long remainSeconds = (ms % ONE_HOUR) / ONE_SECOND;
            return (ms / ONE_HOUR) + "h:" + (remainSeconds / ONE_MINUTE) + "m:" + (remainSeconds % ONE_MINUTE) + "s";
        } else if (ms / ONE_MINUTE > 0) {
            long remainSeconds = (ms % ONE_MINUTE) / ONE_SECOND;
            return (ms / ONE_MINUTE) + "m:" + remainSeconds + "s";
        } else {
            return (ms / ONE_SECOND) + "s";
        }
    }

    public static void loadThumbnail(Context context, long origId, RoundedCornerImageView thumbnailView, Bitmap defaultBitmap) {
        final String imageKey = String.valueOf(origId);
        final Bitmap bitmap = CacheManager.getInstance().getMemoryCache().get(imageKey);

        if (bitmap != null) {
            thumbnailView.setImageBitmap(bitmap);
        } else if (cancelPotentialWork(origId, thumbnailView)) {
            final LoadThumbnailTask task = new LoadThumbnailTask(context, thumbnailView);
            final AsyncDrawable asyncDrawable = new AsyncDrawable(defaultBitmap, task);
            thumbnailView.setImageDrawable(asyncDrawable);
            task.execute(new LoadThumbnailParams(origId));
        }
    }

    /**
     * Returns true if the current work has been canceled or if there was no work in
     * progress on this image view.
     * Returns false if the work in progress deals with the same data. The work is not
     * stopped in that case.
     */
    public static boolean cancelPotentialWork(Object data, RoundedCornerImageView imageView) {
        final LoadThumbnailTask loadPhotoTask = LoadThumbnailTask.getLoadThumbnailTask(imageView);

        if (loadPhotoTask != null) {
            final Object bitmapData = loadPhotoTask.getData();
            if (bitmapData == null || !bitmapData.equals(data)) {
                loadPhotoTask.cancel(true);
            } else {
                // The same work is already in progress.
                return false;
            }
        }
        return true;
    }
}




Java Source Code List

com.example.hellojni.HelloJni.java
com.jasonsoft.mediacodecvideoplayer.LoadThumbnailTask.java
com.jasonsoft.mediacodecvideoplayer.MediaCodecVideoPlayerActivity.java
com.jasonsoft.mediacodecvideoplayer.MenuDrawerBaseActivity.java
com.jasonsoft.mediacodecvideoplayer.RoundedCornerImageView.java
com.jasonsoft.mediacodecvideoplayer.Utils.java
com.jasonsoft.mediacodecvideoplayer.VideoSurfaceView.java
com.jasonsoft.mediacodecvideoplayer.adapter.MenuAdapter.java
com.jasonsoft.mediacodecvideoplayer.cache.CacheManager.java
com.jasonsoft.mediacodecvideoplayer.data.AsyncDrawable.java
com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailParams.java
com.jasonsoft.mediacodecvideoplayer.data.LoadThumbnailResult.java
com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerCategory.java
com.jasonsoft.mediacodecvideoplayer.data.MenuDrawerItem.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java