【问题标题】:Android- launch mp3 from a url linkAndroid- 从 url 链接启动 mp3
【发布时间】:2011-10-23 17:41:18
【问题描述】:

我目前有一个webview,当您按下 mp3 链接时,mp3 将开始播放。我们最近更改了所有链接,它们现在是“https”而不是“http”。我从日志猫收到的错误如下:

08-09 17:26:59.060: ERROR/AndroidRuntime(5574): FATAL EXCEPTION: main
08-09 17:26:59.060: ERROR/AndroidRuntime(5574): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=https://s3.amazonaws.com/StopDropRave/Week+of+August+8/Flawless+ft.+Army+of+Karmen+-+L.I.E.+%28Love+Automatic+Dubstep+Remix%29.mp3 typ=audio/* }
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.app.Activity.startActivityFromChild(Activity.java:3067)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.app.Activity.startActivityForResult(Activity.java:2847)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.app.Activity.startActivity(Activity.java:2933)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at ravebox.dev.sdr.BlogActivity$HelloWebViewClient$1.onClick(BlogActivity.java:158)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.os.Looper.loop(Looper.java:123)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at android.app.ActivityThread.main(ActivityThread.java:3835)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at java.lang.reflect.Method.invokeNative(Native Method)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at java.lang.reflect.Method.invoke(Method.java:507)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-09 17:26:59.060: ERROR/AndroidRuntime(5574):     at dalvik.system.NativeStart.main(Native Method)

我不知道是不是因为 https。不知道。有任何想法吗?谢谢

这是我对这个特定活动的清单的一部分:

<activity android:name=".BlogActivity"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

这也是我处理监听部分的代码的一部分。它实质上打开了一个对话框,用户可以在其中选择收听或下载。下载工作完美,但将链接更改为 https 后收听效果不佳。

private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(final WebView view,
                final String url) {
            view.loadUrl(url);
            view.getSettings().getAllowFileAccess();
            view.getSettings().setJavaScriptEnabled(true);
            view.getCertificate();
            // load the dropbox files so people can listen to the track
            if (url.startsWith("https://") && url.endsWith(".mp3")) {
                view.getCertificate();
                progressWebView.dismiss();
                progressWebView.cancel();
                /*blogDialog.setButton("Listen",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                Intent intent = new Intent(Intent.ACTION_VIEW);
                                intent.setDataAndType(Uri.parse(url), "audio/*");
                                view.getContext().startActivity(intent);

                            }
                        });*/
                blogDialog.setButton2("Download",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                sdrUrl = url.toString();
                                new DownloadFile().execute();

                            }

                        });
                blogDialog.show();

            } else {
                return super.shouldOverrideUrlLoading(view, url);
            }
            return true;
        }
    }

【问题讨论】:

  • 在将链接更改为 https 之前是否进行了播放测试?
  • @Deepak:是的,之前一切都运行良好。没有任何问题。
  • 您能检查一下您的清单文件的意图过滤器吗?看起来过滤器与您要播放的数据类型和类型不匹配?检查“http://”是否在过滤器的某些部分中被硬编码。
  • 我添加了上面清单的那段以及我处理监听部分的代码。下载部分工作正常,但其他部分没有那么多。我不知道它是否由于 https 而我需要某种证书,但它没有要求。

标签: android stream webview android-intent mp3


【解决方案1】:

塞尔吉奥拉, 看起来您有尝试播放任何音频文件的“BlogActivity”。 默认情况下,Android 音乐播放器应用程序将用于播放链接中的数据。 音乐播放器应用程序中的流媒体播放器活动仅将数据方案设置为“http”,因此不会使用“https”方案播放新链接中的内容。

SO 已经有这样的查询,这里是链接,problem in streaming audio from https link

这就是为什么下载可以正常播放但播放不正常的原因。 因此,我建议您在播放之前将文件下载到设备上的临时位置。

【讨论】:

    猜你喜欢
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2016-05-09
    • 1970-01-01
    相关资源
    最近更新 更多