安卓:有没有办法来改变MediaPlayer的网址吗? [英] Android: Is there a way to change MediaPlayer urls?

查看:184
本文介绍了安卓:有没有办法来改变MediaPlayer的网址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法来改变URL,而不必编译应用程序或部署一次,我被推到了市场?该URL可能在将来或指向不同的URL改变。

目前,我硬编码的URL somethign这样的:

  {尝试
 URL =htt​​p://ofertaweb.ro/android/sleepandlovemusic/+ songs_array [计数器] +.MP3
 mediaPlayer.setDataSource(URL);
 }


解决方案

这是我找到了一种方法来读取HTML文件:

 进口java.io.BufferedReader中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.io.InputStreamReader中;进口org.apache.http.Htt presponse;
进口org.apache.http.client.ClientProtocolException;
进口org.apache.http.client.HttpClient;
进口org.apache.http.client.methods.HttpGet;
进口org.apache.http.impl.client.DefaultHttpClient;公共类Get_Webpage {    公共字符串parsing_url =;    公共Get_Webpage(字符串url_2_get){
        parsing_url = url_2_get;
    }    公共字符串get_webpage_source(){        HttpClient的客户端=新DefaultHttpClient();
        HTTPGET请求=新HTTPGET(parsing_url);
        HTT presponse响应= NULL;
        尝试{
            响应= client.execute(请求);
        }赶上(ClientProtocolException E){        }赶上(IOException异常五){        }        串的html =;
        在的InputStream = NULL;
        尝试{
            在= response.getEntity()的getContent()。
        }赶上(IllegalStateException异常五){        }赶上(IOException异常五){        }
        读者的BufferedReader =新的BufferedReader(新的InputStreamReader(中));
        StringBuilder的海峡=新的StringBuilder();
        串线= NULL;
        尝试{
            而((行= reader.readLine())!= NULL)
            {
                str.append(线);
            }
        }赶上(IOException异常五){        }
        尝试{
            附寄();
        }赶上(IOException异常五){        }
        的HTML = str.toString();        返回HTML;
    }}

那么你读到这样的:

  {尝试
    Get_Webpage的obj =新Get_Webpage(http://ofertaweb.ro/android/sleepandlovemusic/list_files.php);
    directory_listings = obj.get_webpage_source();
}赶上(例外五){
    }//Log.d(\"director上市,directory_listings);songs_array = directory_listings.split(:::);

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 hardcoding the urls somethign like this:

 try {
 url = "http://ofertaweb.ro/android/sleepandlovemusic/" + songs_array[counter] + ".mp3";
 mediaPlayer.setDataSource(url);
 } 

解决方案

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;

public class Get_Webpage {

    public String parsing_url = "";

    public Get_Webpage(String url_2_get){       
        parsing_url = url_2_get;
    }

    public String get_webpage_source(){

        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(parsing_url);
        HttpResponse response = null;
        try {
            response = client.execute(request);
        } catch (ClientProtocolException e) {

        } catch (IOException e) {

        }

        String html = "";
        InputStream in = null;
        try {
            in = response.getEntity().getContent();
        } catch (IllegalStateException e) {

        } catch (IOException e) {

        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = 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_Webpage obj = new Get_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(":::");

这篇关于安卓:有没有办法来改变MediaPlayer的网址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆