奇怪的错误与果冻豆视频意向 [英] Weird error with video Intent on Jelly Bean

查看:181
本文介绍了奇怪的错误与果冻豆视频意向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到视频奇怪的错误意图,我没有经历过,直到Android的4.1。

I'm experiencing a weird error with video Intents that I haven't experienced until Android 4.1.

下面是我的code关于开展意图。我和其他MIME类型尝试,以及包括的视频/ MP4 的,但通配符(视频/ 的*)应该工作就好了,据官方Android开发者网站上意图和意图过滤器

Here's my code for launching the Intent. I've tried with other MIME types as well, including video/mp4, but the wildcard (video/*) is supposed to work just fine, according to the official Android developer site on Intents and Intent filters.

Intent videoIntent = new Intent();
videoIntent.setAction(Intent.ACTION_VIEW);
videoIntent.setData(Uri.parse(fileUrl));
videoIntent.setType("video/*");

startActivity(videoIntent);

在我的设备,无论是运行Android 4.1,这导致了一个 ActivityNotFoundException ,因为它说没有安装的应用程序能够处理的意图。这是奇怪的,因为它一直工作在Android上的所有previous版本,它应该在默认的视频播放器推出。

On my devices, both running Android 4.1, this results in an ActivityNotFoundException, because it says no installed applications can handle the Intent. This is weird because it's been working on all previous versions of Android, and it should launch in the default video player.

许多第三方视频播放器能够处理的意图,所以我不知道为什么它不使用默认的视频播放器的工作了。

Many third party video players are capable of handling the Intent, so I'm wondering why it's not working with the default video player anymore.

任何想法?

这似乎是同样的问题:

<一个href=\"http://stackoverflow.com/questions/12931019/video-player-not-working-on-jelly-bean-device-android-content-activitynotfounde?rq=1\">Video播放器不工作果冻豆设备上:android.content.ActivityNotFoundException

推荐答案

我设法找到与别人一点帮助的解决方案。看来,的setType()呼叫清除任何previously附加数据,包括使用setData()电话。每文档:

I managed to find a solution with a bit of help from someone else. It seems that the setType() call clears any previously attached data, including the setData() call. Per the documentation:

此方法会自动清除,这是previously设置的任何数据(
  例如,通过使用setData(URI))。

This method automatically clears any data that was previously set (for example by setData(Uri)).

当我改成了 setDataAndType()相反,它的工作。看来,这不是与果冻豆的问题毕竟,幸运的是: - )

When I changed it to setDataAndType() instead, it worked. It appears that it wasn't an issue with Jelly Bean after all, thankfully :-)

下面是最终code创建视频意图:

Here's the final code for creating the video intent:

public static Intent getVideoIntent(String fileUrl) {
    Intent videoIntent = new Intent(Intent.ACTION_VIEW);
    videoIntent.setDataAndType(Uri.fromFile(new File(fileUrl)), getMimeType(fileUrl));

    return videoIntent;
}

public static String getMimeType(String url) {
    String type = null;
    String extension = MimeTypeMap.getFileExtensionFromUrl(url);

    if (extension != null) {
        MimeTypeMap mime = MimeTypeMap.getSingleton();
        type = mime.getMimeTypeFromExtension(extension);

        if (TextUtils.isEmpty(type))
            type = "video/*"; // No MIME type found, so use the video wildcard
    }

    return type;
}

这篇关于奇怪的错误与果冻豆视频意向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆