Android Open Source - HelloWebView Media Util






From Project

Back to project page HelloWebView.

License

The source code is released under:

Apache License

If you think the Android project HelloWebView 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.mengdd.hellowebview.utils;
//from w  ww  .ja  v a2s. co  m
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class MediaUtil {

    private final static String MIMETYPE_OCTET_STREAM = "application/octet-stream";

    public static boolean playMedia(Context context, String url, String mimeType) {
        if (!isVideoType(mimeType)) {
            return false;
        }
        // ??????, ??????????
        return playMediaForUserSelect(context, url, mimeType);
    }

    public static boolean isVideoType(String mimeType) {
        int fileType = MediaFile.getFileTypeForMimeType(mimeType);
        if (MIMETYPE_OCTET_STREAM.equals(mimeType)) {

            return false;
        }

        // cctv'live format: application/vnd.apple.mpegurl
        return MediaFile.isVideoFileType(fileType)
                || "video/*".equalsIgnoreCase(mimeType)
                || "application/vnd.apple.mpegurl".equals(mimeType);
    }

    /**
     * Users choose a app to play media
     */
    private static boolean playMediaForUserSelect(Context c, String url,
            String mimetype) {
        Intent intent = BrowserUtils.newIntentFromSelf(Intent.ACTION_VIEW);
        Uri name = Uri.parse(url);
        intent.setDataAndType(name, mimetype);
        try {
            c.startActivity(intent);
        }
        catch (ActivityNotFoundException e) {
            return false;
        }
        return true;
    }

}




Java Source Code List

com.mengdd.download.DownloadManager.java
com.mengdd.download.Downloader.java
com.mengdd.download.OnDownloadChangedAdapter.java
com.mengdd.download.OnDownloadChangedListener.java
com.mengdd.hellowebview.Constants.java
com.mengdd.hellowebview.MainActivity.java
com.mengdd.hellowebview.utils.BrowserUtils.java
com.mengdd.hellowebview.utils.DeviceUtils.java
com.mengdd.hellowebview.utils.FileUtils.java
com.mengdd.hellowebview.utils.IOUtils.java
com.mengdd.hellowebview.utils.LogUtil.java
com.mengdd.hellowebview.utils.MediaFile.java
com.mengdd.hellowebview.utils.MediaUtil.java
com.mengdd.hellowebview.utils.PreferencesUtils.java
com.mengdd.hellowebview.utils.ReleaseConfig.java