在Eclipse中如何有传入的一个打开网址 [英] In eclipse how to have a open url passed in

查看:121
本文介绍了在Eclipse中如何有传入的一个打开网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的节目,而是通过确定已经找到一种方法,使一个应用程序,允许媒体URL通过我的应用程序可以发挥的问题即时试图让这个它的开放更是1某个网址具体歌曲进出口试图让这个被网站上已经设置了播放列表可以通过该播放器可以选择,如果有人达到帮助我学习,或服用时间通过电子邮件或短信与我合作,请让我知道在codeI至今为这个应用程序如下:

  @覆盖
保护无效的onCreate(捆绑savedInstanceState){
    // TODO自动生成方法存根
    super.onCreate(savedInstanceState);字符串URL =htt​​p://beatswith.us/uploads/Mac%20Miller%20-%20Paper%20Route%20feat.%20Kev%20Da%20Hustla.mp3; //此处是您的网址
的MediaPlayer媒体播放器=新的MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
尝试{
    mediaPlayer.setDataSource(URL);}赶上(抛出:IllegalArgumentException五){
    // TODO自动生成catch块
    e.printStackTrace();
}赶上(IllegalStateException异常五){
    // TODO自动生成catch块
    e.printStackTrace();
}赶上(IOException异常五){
    // TODO自动生成catch块
    e.printStackTrace();
}
尝试{
    媒体播放器prepare()。
}赶上(IllegalStateException异常五){
    // TODO自动生成catch块
    e.printStackTrace();
}赶上(IOException异常五){
    // TODO自动生成catch块
    e.printStackTrace();
} //可能需要很长时间! (用于缓冲等)
mediaPlayer.start();
}
};


解决方案

所以,如果我读了你的问题吧,这听起来像你现在刚一首歌你的应用程序将发挥,而是要能够从选择歌曲列表播放..

什么你可能会想要做一个下一个步骤是创建一个歌曲数组,然后使用ListView控件让用户选择他们想打哪首歌。它看起来像这可能是你第一次的编程。我建议你​​看一些tuturials展示如何列表视图的作品,然后进行绑定到你的ListView的ArrayAdapter ..一个ArrayAdapter一个数组(想想阵列的作为是在有超过1东西的变量,在你的案件串从而重新present URL的歌曲..

下面是一些code,让你开始:

 公共类SongListActivity扩展ListActivity {
    静态最后的String [] =的SongList新的String [] {
       http://beatswith.us/uploads/Mac%20Miller%20-%20Paper%20Route%20feat.%20Kev%20Da%20Hustla.mp3
       http://beatswith.us/another1.mp3
       http://beatswith.us/another2.mp3
    };    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
     ArrayAdapter songAdapter =新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_1,的SongList);
     setListAdapter(songAdapter);    }    @覆盖
    保护无效onListItemClick(LV的ListView,视图V,INT POS,长I​​D){
      字符串URL =(字符串)lv.getAdapter()的getItem(POS)。
      playSong(URL);    }
    私人无效playSong(字符串URL){
      的MediaPlayer媒体播放器=新的MediaPlayer();
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      尝试{
         mediaPlayer.setDataSource(URL);
         mediaPlayer.start();
      }赶上(例外五){
         e.printStackTrace();
      }
    }
}

下面是更多的文档应该有所帮助:
http://developer.android.com/reference/android/app/ListActivity.html

您将需要更新与有效的URL的歌曲阵列。

- 更新 -
我有点仍然困惑的确切的问题..我不知道正是你想做的事情。如果有一个网站(也许在XML格式)的播放列表你可以下载该XML文件,然后作出ListAdapter,你会改用一个ArrayAdapter的。我的意思是真的这得到更加复杂,因为在现实中,你可能想显示歌曲的名称,以便意味着你需要解析从MP3的ID3信息 - 这是比较容易做,但它绝对是比你目前的code不..我的例子应该给你就如何发挥的歌曲列表,应该得到你之前多一点编程经验有点想法更多地参与转移到更复杂的事情。

I am very new to programming but through determination have found a way to make an application that allows a media url to be played through my app the issue is im trying to make it so that its open to more that 1 specific url for that specific song Im trying to make it so that a playlist that is already set on a site can be chosen through this player if anyone is up to helping me learn and or taking the time to work with me through email or messaging please let me know the code i have so far for this app is as follows

    @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

String url = "http://beatswith.us/uploads/Mac%20Miller%20-%20Paper%20Route%20feat.%20Kev%20Da%20Hustla.mp3"; // your URL here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
    mediaPlayer.setDataSource(url);

} catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IllegalStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
try {
    mediaPlayer.prepare();
} catch (IllegalStateException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} // might take long! (for buffering, etc)
mediaPlayer.start();
}
};

解决方案

So if I'm reading your question right, it sounds like you currently have just one song your app will play but instead you want to be able to choose from a list of songs to play..

What you probably would want to do as a next step is create an array of songs and then use ListView to allow the user to pick which song they want to play. It looks like this may be your first time programming. I suggest you look up some tuturials showing how a list view works and then make an ArrayAdapter to bind to your ListView.. The ArrayAdapter has an array (think of an array as being a variable that has more than 1 thing in it, in your case Strings which represent URL's to songs..

Here is some code to get you started:

 public class SongListActivity extends ListActivity {
    static final String[] songList = new String[] {  
       "http://beatswith.us/uploads/Mac%20Miller%20-%20Paper%20Route%20feat.%20Kev%20Da%20Hustla.mp3",
       "http://beatswith.us/another1.mp3",
       "http://beatswith.us/another2.mp3"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
     ArrayAdapter songAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, songList);
     setListAdapter(songAdapter);



    }

    @Override
    protected void onListItemClick(ListView lv, View v,int pos, long id) {
      String url = (String) lv.getAdapter().getItem(pos);
      playSong(url);

    }


    private void playSong(String url) {
      MediaPlayer mediaPlayer = new MediaPlayer();
      mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      try {
         mediaPlayer.setDataSource(url);
         mediaPlayer.start();
      } catch (Exception e) {
         e.printStackTrace();
      } 
    }
}

here is more documentation that should help: http://developer.android.com/reference/android/app/ListActivity.html

You will need to update the array with valid URL's to songs.

-- Update -- I'm a bit confused still by the exact question.. I'm not sure what exactly you want to do.. If there is a playlist on a website (perhaps in xml format) you could download that xml file and then make a ListAdapter that you would use instead of an ArrayAdapter.. I mean really this gets much more complicated because in reality you probably want to show the name of the song so that means you need to parse the ID3 information from the mp3 -- which is relatively easy to do but it is definitely much more involved than what your current code does.. My example should give you a bit of an idea on how to play a list of songs and should get you a bit more programming experience before you move on to more complicated things.

这篇关于在Eclipse中如何有传入的一个打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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