Android:有没有办法更改MediaPlayer网址?(Android: Is there a way to change MediaPlayer urls?)

系统教程 行业动态 更新时间:2024-06-14 16:59:46
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(":::");

更多推荐

本文发布于:2023-04-17 08:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/5180c1eff0dc4be1b738f1d8d3182605.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   网址   Android   MediaPlayer   urls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!