Android:有没有办法更改MediaPlayer网址?(Android: Is there a way to change MediaPlayer urls?)
有没有办法在我推入市场后更改网址而不编译应用程序或部署? 网址可能会在将来发生变化或指向不同的网址。
目前我正在硬编码这样的网址:
try { url = "http://ofertaweb.ro/android/sleepandlovemusic/" + songs_array[counter] + ".mp3"; mediaPlayer.setDataSource(url); }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); }最满意答案
不要在项目构建时硬编码URL,考虑编写在应用程序运行时动态解析它的代码。 例如,你可以创建一个静态html页面(包含一个实际的mp3 URL列表),在项目构建时硬编码这个静态html页面URL,每次你的应用程序开始运行时,查询这个静态html页面以获得最新的应用程序运行时的日期mp3 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(":::");更多推荐
发布评论