Esempio n. 1
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   this.requestWindowFeature(Window.FEATURE_NO_TITLE);
   setContentView(R.layout.activity_play);
   initializeComponent();
   Intent intent = PlayActivity.this.getIntent();
   String data = intent.getStringExtra("MEDIA_DATA");
   txtSongTitle.setText(intent.getStringExtra("MEDIA_TITLE"));
   txtArtist.setText(intent.getStringExtra("MEDIA_ARTIST"));
   txtTotalDuration.setText(intent.getStringExtra("MEDIA_DURATION"));
   mediaPlayer = new MediaPlayer();
   try {
     mediaPlayer.setDataSource(data);
     mediaPlayer.prepare();
   } catch (IllegalArgumentException | SecurityException | IllegalStateException | IOException e) {
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  private void prepare() {
    mp = new MediaPlayer();
    try {
      //        	mp.setDataSource("http://forum.ea3w.com/coll_ea3w/attach/2008_10/12237832415.3gp");
      //
      //	mp.setDataSource("http://res.happyge.com:8081/client/test2/101/10101/101010100/img/400000.mp4");
      mp.setDataSource(url);
      mp.prepareAsync();
    } catch (IllegalArgumentException | SecurityException | IllegalStateException | IOException e) {
      e.printStackTrace();
    }
    mp.setOnBufferingUpdateListener(
        new OnBufferingUpdateListener() {

          @Override
          public void onBufferingUpdate(MediaPlayer mp, int percent) {}
        });
    mp.setOnCompletionListener(
        new MediaPlayer.OnCompletionListener() {

          @Override
          public void onCompletion(MediaPlayer mp) {
            state = VideoState.stop;
            ivStart.setVisibility(View.VISIBLE);
            ivStop.setVisibility(View.INVISIBLE);
            ivPause.setVisibility(View.INVISIBLE);
          }
        });
    mp.setOnPreparedListener(
        new OnPreparedListener() {

          @Override
          public void onPrepared(MediaPlayer mp) {
            mIsVideoReadyToBePlayed = true;
            mp.seekTo(0);
            startVideoPlayback();
          }
        });
    mp.setOnVideoSizeChangedListener(
        new OnVideoSizeChangedListener() {

          @Override
          public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {

            if (width == 0 || height == 0) {
              return;
            }
            //				if (width > AppInfo.getScreenWidth()) {
            double d = (double) AppInfo.getScreenWidth() / width;
            width = AppInfo.getScreenWidth();
            height = (int) (height * d);
            //				}
            mIsVideoSizeKnown = true;
            mVideoWidth = width;
            mVideoHeight = height;

            startVideoPlayback();
          }
        });
    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
  }