启动后从SD卡播放视频

发布于 2025-01-06 03:19:13 字数 929 浏览 1 评论 0原文

我有一个通过 BroadcastReceiver 自动启动的应用程序,并在 Android 2.3.3 上设置为主屏幕。 HTC Desire HD 上的 API10。

应用程序应在启动后立即重复播放视频,但由于 SD 卡尚未准备好,它会终止应用程序并显示强制关闭错误消息,该消息不会消失。

至少我认为这是因为sdcard。

在后台,主屏幕重新启动,但错误消息并没有消失,如果几秒钟后消失也没有问题,但如果根本不出现那就更严重了..

你能帮忙吗我? 谢谢!

编辑#1: 这将检查 SD 卡是否准备就绪。我只需要读取权限..

static public boolean hasStorage(boolean requireWriteAccess) {

    String state = Environment.getExternalStorageState();
    Log.v("tomi", "storage state is " + state);

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        if (requireWriteAccess) {
            boolean writable = checkFsWritable();
            Log.v("tomi", "storage writable is " + writable);
            return writable;
        } else {
            return true;
        }
    } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}

I have an app which is autostarting via BroadcastReceiver and is set as a homescreen on Android 2.3.3. API10 on an HTC Desire HD.

The app should play a video repeatedly right after starting, but as the sdcard is not ready it kills the application with a force close error message which doesn't go away.

At least I think it is because of the sdcard.

In the background, the homescreen restarts but the error message doesn't go away, it would be no problem if it would disappear a few seconds later, but it would be even greater if it wouldn't appear at all..

can you help me?
thanks!

edit #1:
this checks if the sdcard is ready. i only need read access..

static public boolean hasStorage(boolean requireWriteAccess) {

    String state = Environment.getExternalStorageState();
    Log.v("tomi", "storage state is " + state);

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        if (requireWriteAccess) {
            boolean writable = checkFsWritable();
            Log.v("tomi", "storage writable is " + writable);
            return writable;
        } else {
            return true;
        }
    } else if (!requireWriteAccess && Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        return true;
    }
    return false;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2025-01-13 03:19:13

你有解决办法吗?

首先,您不需要“通过 BroadcastReceiver 自动启动”和“设置为主屏幕”。一个就足够了,最好是后者。

活动启动后,它可以检查Environment以查看外部存储是否准备就绪。如果没有,它可以为 ACTION_MEDIA_MOUNTED 注册一个接收器,以了解外部存储何时准备就绪。一旦准备好——并且只有在那时——它就可以尝试播放视频。

do you have a solution for this?

First, you should not need both "autostarting via BroadcastReceiver" and "set as a homescreen". One should suffice, preferably the latter.

Once the activity launches, it can check Environment to see if external storage is ready. If not, it can register a receiver for ACTION_MEDIA_MOUNTED to find out when external storage becomes ready. Once it is ready -- and only at that point -- it can try to play the video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文