Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url encoding not supported

I have file online. I am trying to play it using media player using live streaming. But media player gives an error (-1,1004) I think my media player not getting correct url as it contains arabic characters so i tried encode it with Html.encode or UrlEncoder class still getting same error.

So at last i loaded that url in webview and on page loading finish i passed webpage url to media player.

    WebView webView = new WebView(SongActivity.this);
        webView.setSoundEffectsEnabled(false);
        webView.loadUrl("MY URL");
        webView.setWebViewClient(new WebViewClient() {
            public void onPageFinished(WebView view, String url) {

                try {

                playerService.startPlay(url );// this passes url to media player and url will be played using media player

                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalStateException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            };

            public void onPageStarted(WebView view, String url,
                    android.graphics.Bitmap favicon) {
                System.out.println("Decoding url:" + strURl);
            };
        });

Its working fine ,also m able to play song but this is not standard one. For normal url (that don't have arabic characters )media player code working great.

Can you provide me some standard solution on it???

like image 346
Swapnil Deshmukh Avatar asked Nov 13 '22 11:11

Swapnil Deshmukh


1 Answers

Based on error code (-1,1004) it seems you might get HTTP 403 Forbidden as an answer from server. Have you tried Uri.encode(String).toString() before mediaPlayer.setDataSource(String url)?

From https://stackoverflow.com/a/4571518/262462:

Don't use the URLEncoder class! Despite the name, that class actually does HTML form encoding, not URL encoding.

like image 59
Kuitsi Avatar answered Nov 15 '22 06:11

Kuitsi