Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Android media player won't start

Android media player won't start

Scheduled Pinned Locked Moved Android
androidannouncement
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pavlex4
    wrote on last edited by
    #1

    I have created android application to stream online radio stations but when I click start button to play radio it won't start.In service I read ip address of file from url and add it to string.When user selects radio station I add port to string with ip address.

    public class BackgroundService extends Service implements OnCompletionListener
    {
    MediaPlayer mediaPlayer;
    private String STREAM_URL;
    final String textSource = "http://audiophileradio.stream/Ip.txt";

        @Override
        public IBinder onBind(Intent intent) {
            return null;
        }
    
        @Override
        public void onCreate()
        {
    
        }
    
        @Override
        public int onStartCommand(Intent intent, int flags, int startId)
        {
            new MyTask().execute();
    
            return START\_STICKY;
        }
    
        public void onDestroy() {
            if (mediaPlayer.isPlaying()) {
                mediaPlayer.stop();
            }
            mediaPlayer.release();
        }
    
        public void onCompletion(MediaPlayer \_mediaPlayer) {
            stopSelf();
        }
    
    
        @Override
        public boolean onUnbind(Intent intent)
        {
            return super.onUnbind(intent);
        }
    
        private class MyTask extends AsyncTask
        {
            String textResult;
    
            @Override
            protected String doInBackground(Void... params) {
    
                URL textUrl;
    
                try {
                    textUrl = new URL(textSource);
    
                    BufferedReader bufferReader
                            = new BufferedReader(new InputStreamReader(textUrl.openStream()));
    
                    String StringBuffer;
                    String stringText = "";
                    while ((StringBuffer = bufferReader.readLine()) != null) {
                        stringText += StringBuffer;
                    }
                    bufferReader.close();
    
                    textResult = stringText;
                    return textResult;
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                    textResult = e.toString();
                } catch (IOException e) {
                    e.printStackTrace();
                    textResult = e.toString();
                }
    
                return null;
    
            }
    
            @Override
            protected void onPostExecute(String resul
    
    P 1 Reply Last reply
    0
    • P Pavlex4

      I have created android application to stream online radio stations but when I click start button to play radio it won't start.In service I read ip address of file from url and add it to string.When user selects radio station I add port to string with ip address.

      public class BackgroundService extends Service implements OnCompletionListener
      {
      MediaPlayer mediaPlayer;
      private String STREAM_URL;
      final String textSource = "http://audiophileradio.stream/Ip.txt";

          @Override
          public IBinder onBind(Intent intent) {
              return null;
          }
      
          @Override
          public void onCreate()
          {
      
          }
      
          @Override
          public int onStartCommand(Intent intent, int flags, int startId)
          {
              new MyTask().execute();
      
              return START\_STICKY;
          }
      
          public void onDestroy() {
              if (mediaPlayer.isPlaying()) {
                  mediaPlayer.stop();
              }
              mediaPlayer.release();
          }
      
          public void onCompletion(MediaPlayer \_mediaPlayer) {
              stopSelf();
          }
      
      
          @Override
          public boolean onUnbind(Intent intent)
          {
              return super.onUnbind(intent);
          }
      
          private class MyTask extends AsyncTask
          {
              String textResult;
      
              @Override
              protected String doInBackground(Void... params) {
      
                  URL textUrl;
      
                  try {
                      textUrl = new URL(textSource);
      
                      BufferedReader bufferReader
                              = new BufferedReader(new InputStreamReader(textUrl.openStream()));
      
                      String StringBuffer;
                      String stringText = "";
                      while ((StringBuffer = bufferReader.readLine()) != null) {
                          stringText += StringBuffer;
                      }
                      bufferReader.close();
      
                      textResult = stringText;
                      return textResult;
                  } catch (MalformedURLException e) {
                      e.printStackTrace();
                      textResult = e.toString();
                  } catch (IOException e) {
                      e.printStackTrace();
                      textResult = e.toString();
                  }
      
                  return null;
      
              }
      
              @Override
              protected void onPostExecute(String resul
      
      P Offline
      P Offline
      Pavlex4
      wrote on last edited by
      #2

      I have fixed the problem! Radio didn't work because I forgot to add http:// in ip address after reading it from url !!!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups