Search code examples
androidstreamwebviewandroid-intentmp3

Android- launch mp3 from a url link


I currently have a webview that when you press a mp3 link, the mp3 will start playing. We recently changed all of the links, and they are now "https" instead of "http". The error I receive from my log cat is the following:

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)

I don't know if its because of the https or not. No idea. any ideas? thanks

This is the portion of my manifest of this particular activity:

<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>

Also here is part of my code where I handle the listening portion. It essentially open a dialog where the user can select to listen or download. the download works perfect, but the listening does not after changing the links to 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;
        }
    }

Solution

  • SergioRa, Looks like you have the 'BlogActivity' from which you are trying to play any audio file. By default the Android Music player app will be used to play the data from the links. The Streaming player activity in Music player application has data scheme set to "http" only and hence will not play content from your new links with "https" scheme.

    SO has already such query and here is the link, problem in streaming audio from https link

    That is the reason why the download works fine but the playback does not. So i would suggest you to download the file to a temporary location on your device before you play it.