Skip to content Skip to sidebar Skip to footer

Android: Is There A Way To Change Mediaplayer Urls?

is there a way to change the urls without compiling the app or deployment once i pushed to the market? the url might change in future or point to different urls. currently i am har

Solution 1:

Do not hardcode your URL at project build time, consider writing code that dynamically resolve it at application run time. for example, you can create a static html page (contains a list of actual mp3 URLs), hardcode this static html page URL at project build time, every time your application starting running, query this static html page to get the up-to-date mp3 URL at application run time. there are many alternative way to achieve this, just give you some clue, hope this helps.

Solution 2:

here is what i found a way to read the html file:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

publicclassGet_Webpage {

    publicStringparsing_url="";

    publicGet_Webpage(String url_2_get){       
        parsing_url = url_2_get;
    }

    public String get_webpage_source(){

        HttpClientclient=newDefaultHttpClient();
        HttpGetrequest=newHttpGet(parsing_url);
        HttpResponseresponse=null;
        try {
            response = client.execute(request);
        } catch (ClientProtocolException e) {

        } catch (IOException e) {

        }

        Stringhtml="";
        InputStreamin=null;
        try {
            in = response.getEntity().getContent();
        } catch (IllegalStateException e) {

        } catch (IOException e) {

        }
        BufferedReaderreader=newBufferedReader(newInputStreamReader(in));
        StringBuilderstr=newStringBuilder();
        Stringline=null;
        try {
            while((line = reader.readLine()) != null)
            {
                str.append(line);
            }
        } catch (IOException e) {

        }
        try {
            in.close();
        } catch (IOException e) {

        }
        html = str.toString();

        return html;
    }

}

then you read like this:

try {
    Get_Webpageobj=newGet_Webpage("http://ofertaweb.ro/android/sleepandlovemusic/list_files.php");
    directory_listings = obj.get_webpage_source();
} catch (Exception e) {
    }

//Log.d("director listing", directory_listings);

songs_array = directory_listings.split(":::");

Post a Comment for "Android: Is There A Way To Change Mediaplayer Urls?"