0

I have a problem playing (streaming) MP3 files using Android's Media Player. My idea is to read NFC tag and place that data URL into a string (songs_urls). After that, media player should use that string and play file from that link.

Everything works fine when I define link, for example String link = "www.blabla.com/audiofile.mp3", but the problem is when I want to read it from the NFC tag.

I have followed this tutorial to build Media Player: http://www.youtube.com/watch?v=LKL-efbiIAM. Everything regarding Media Player is in onCreate() function. NFC part is in the onResume() function. So I have, just moved the Media Player code below from onCreate() to onResume().

Here is the MP code I've moved to onResume():

  ImageButton btn_play = (ImageButton) findViewById(R.id.imageButton3);

    btn_play.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            txt_song_title.setText(songs_urls);



            try {
                mediaPlayer.setDataSource(songs_urls);
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SecurityException 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();
            }
            mediaPlayer.start();

        }
    });

The line

txt_song_title.setText(songs_urls);

works (text changes) but everything below (in try/catch blocks) doesn't work - the file can't be played.

Thanks in advance.

  • Could you read the tag's URL? Or is there just a problem to link it to the mediaplayer? – pizzaani Mar 04 '14 at 22:17
  • Yes, I can read the content of the tag. And, as I wrote, the line `setText` works well - the content of tag (in this case, the URL) shows in the TextView area normally. So, I guess the problem is that media player doesn't accept that link read from the NFC tag. I have read about some problems that might be causing this. They are regarding strange additional characters: [link](http://stackoverflow.com/questions/7917567/strange-character-on-android-ndef-record-payload). But the thing is - mine setText method shows the link just normal, without that square on the beginning but play doesn't start. – user3047537 Mar 06 '14 at 01:54
  • How did you check that the characters are okay? Did you put out the link as hex values? Maybe if you could do a byte-by-byte verification of the tag's string with a given string. – pizzaani Mar 06 '14 at 08:44

0 Answers0