Android Open Source - android-AppPuntalRadio Radio Manager






From Project

Back to project page android-AppPuntalRadio.

License

The source code is released under:

GNU General Public License

If you think the Android project android-AppPuntalRadio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ivanob.puntalradio.model;
//from w  w  w .j  av a2s . co m
import java.io.IOException;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.ivanob.puntalradio.R;
import com.ivanob.puntalradio.R.string;

import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.widget.Toast;

public class RadioManager {
  
  private StationConfigManager stationManager = StationConfigManager.getInstance();
  private static RadioManager instance = null;
  private MediaPlayer mp;
  private Context context;
  private boolean isPlaying;
  
  public static RadioManager getInstance(Context context) {
    if(instance == null) {
      instance = new RadioManager(context);
    }
    return instance;
  }
  
  public boolean isPlaying(){
    return isPlaying;
  }

  private RadioManager(Context context){
    this.context=context;
    mp = new MediaPlayer();
    isPlaying=true;
    try {
          mp.setDataSource(stationManager.getStationURL());
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
            public void onBufferingUpdate(MediaPlayer mp, int percent) {
                //playSeekBar.setSecondaryProgress(percent);
                //Log.i("Buffering", "" + percent);
            }
        });
        mp.prepareAsync();

        mp.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
              resumePlayer();
              isPlaying=true;
            }
        });
  }
  
  public void pausePlayer(){
      mp.pause();
      isPlaying=false;
    }
  
  public void resumePlayer(){
    mp.start();
    isPlaying=true;
    Toast.makeText(context, 
        context.getResources().getString(R.string.connected_msg),
        Toast.LENGTH_SHORT).show();
  }
  
  public void stopPlayer(){
    mp.stop();
    mp.release();
    isPlaying=false;
  }
}




Java Source Code List

com.ivanob.puntalradio.AboutDialog.java
com.ivanob.puntalradio.AppSectionsPagerAdapter.java
com.ivanob.puntalradio.Consts.java
com.ivanob.puntalradio.MainActivity.java
com.ivanob.puntalradio.ParrillaFragment.java
com.ivanob.puntalradio.PortadaFragment.java
com.ivanob.puntalradio.ProgramInfoDialog.java
com.ivanob.puntalradio.ProgramasFragment.java
com.ivanob.puntalradio.TimerSleepMode.java
com.ivanob.puntalradio.model.RadioManager.java
com.ivanob.puntalradio.model.RadioProgram.java
com.ivanob.puntalradio.model.RadioProgrammingManager.java
com.ivanob.puntalradio.model.StationConfigManager.java