@Override
        public void run() {
          if (nextItemIndex >= slideshow.size()) {
            // if there is music playing
            if (mediaPlayer != null && mediaPlayer.isPlaying())
              mediaPlayer.reset(); // slideshow done, reset mediaPlayer
            finish(); // return to launching Activity
          } // end if
          else {
            MediaItem item = slideshow.getMediaItemAt(nextItemIndex);

            if (item.getType() == MediaItem.MediaType.IMAGE) {
              imageView.setVisibility(View.VISIBLE); // show imageView
              videoView.setVisibility(View.INVISIBLE); // hide videoView
              new LoadImageTask().execute(Uri.parse(item.getPath()));
            } // end if
            else {
              imageView.setVisibility(View.INVISIBLE); // hide imageView
              videoView.setVisibility(View.VISIBLE); // show videoView
              playVideo(Uri.parse(item.getPath())); // plays the video
            } // end else

            ++nextItemIndex;
          } // end else
        } // end method run
Пример #2
0
  public void gotoPrevTrack() {

    Log.i(TAG, "REWIND MUSIC");
    if (mPlayer != null && !mLastSong.isEmpty()) {

      mPlayer.stop();

      mIsPrepared = false;

      // set the mSong to the last song added in the []
      mSong = mLastSong.get(mLastSong.size() - 1);

      // remove the last index from the []
      mLastSong.remove(mLastSong.size() - 1);

      try {
        // rest the player back to an idle state
        mPlayer.reset();

        // reset the datasource to the mSong that was updated
        mPlayer.setDataSource(this, Uri.parse(mSongResource[mSong]));

      } catch (IOException e) {
        e.printStackTrace();
      }

      mPlayer.prepareAsync();

      mPlayWhenPrepared = true;

    } else { // if the player is null or the array is empty

      Toast.makeText(this, "No Previous Track Available", Toast.LENGTH_SHORT).show();
    }
  }
Пример #3
0
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
      // not ready for playback just yet, will try again later
      return;
    }

    if (mMediaPlayer != null) {
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
    }
    try {
      mMediaPlayer = new MediaPlayer();
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mIsPrepared = false;
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;
      mMediaPlayer.setDataSource(mContext, mUri);
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      attachMediaController();
    } catch (IOException ex) {
      Log.w("VideoView", "Unable to open content: " + mUri, ex);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w("VideoView", "Unable to open content: " + mUri, ex);
      return;
    }
  }
 public boolean onError(MediaPlayer mp, int what, int extra) {
   mp.reset();
   if (null != mParent) {
     mParent.mediaEvent(MediaEventsHandler.MEDIA_PLAYING_FAILED);
   }
   return false;
 }
Пример #5
0
  @Override
  public void onCreate() {

    feedBackIntent = new Intent(BROADCAST_FEEDBACK);
    seekIntent = new Intent(BROADCAST_SEEK);

    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    mediaPlayer.setOnBufferingUpdateListener(this);
    mediaPlayer.setOnInfoListener(this);
    mediaPlayer.setOnSeekCompleteListener(this);
    mediaPlayer.setOnPreparedListener(this);
    mediaPlayer.reset();

    DropboxConnect dropConnect = new DropboxConnect(getApplicationContext());
    dropboxApi = dropConnect.getDropboxAPI();

    nowplayingData = SongSQLite.getmInstance(getApplicationContext());
    playingSongList = nowplayingData.getAllSong(SongSQLite.TABLE_NOWPLAYING, null);
    intCurrentSong = 0;

    if (playingSongList == null) playingSongList = new ArrayList<>(); // If Database is Emply

    intTotalSong = playingSongList.size();
    updateCurrentSong();

    initNotification();
    Log.d(">>>> THAI <<<<", "onCreat() Service");
  }
Пример #6
0
 /** If Media player is playing then stop it restart it after that create an intent to inform. */
 private void stopSong() {
   if (mPlayer.isPlaying()) {
     mPlayer.stop();
   }
   mPlayer.reset();
   sendBr(IM_PAUSE);
 }
  public void playSong(final ViewHolder holder, String name) {
    if (isPlaying == false) {
      try {

        String path = name;
        gus.setDataSource(root + "/" + path);
        gus.setOnCompletionListener(
            new MediaPlayer.OnCompletionListener() {

              @Override
              public void onCompletion(MediaPlayer mp) {
                holder.myImageButton.setBackgroundResource(R.drawable.play);
                isPlaying = false;
              }
            });
        gus.prepare();
        gus.start();
        Log.d("is playing", "true");
        isPlaying = true;
        holder.myImageButton.setBackgroundResource(R.drawable.pausebtn);

      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {

      gus.pause();
      gus.reset();
      isPlaying = false;
      holder.myImageButton.setBackgroundResource(R.drawable.play);
    }
  }
        @Override
        public void callback(final MediaPlayer player, final String url) {
          Trace.e(tag, "callback:" + url);
          if (init) {
            init = false;
            if (!TextUtils.isEmpty(url)) {
              mUrl = url;
            }
            mHandler.removeCallbacks(runnable);
            mHandler.postDelayed(runnable, 800);
            return;
          }
          mHandler.removeCallbacks(runnable);
          if (!TextUtils.isEmpty(url) && player != null && (mUrl == null || !mUrl.equals(url))) {
            mUrl = url;
            player.reset();

            Intent intent = VideoActivity.getIntent(context, mUrl, title);
            intent.putExtra(IS_FROM_PLAYER_ON_LINE_VIDEO_ACTIVITY, true);
            startActivityForResult(intent, REQUEST_PLAYER_ONLINE_VIDEO_ACTIVITY);
            finish();
          } else {
            mHandler.postDelayed(runnable, 800);
          }
        }
Пример #9
0
 public MusicItem play(
     final Context context, final ArrayList<MusicItem> list, final int position) {
   if (playing == Config.PlayState.STATE_PLAYING) {
     mediaPlayer.reset();
   }
   mediaPlayer =
       MediaPlayer.create(context, Uri.parse("file://" + list.get(position).getFilename()));
   try {
     // mediaPlayer.prepare();
     mediaPlayer.start();
     this.context = context;
     this.list = list;
     this.position = position;
     mediaPlayer.setOnCompletionListener(
         new MediaPlayer.OnCompletionListener() {
           @Override
           public void onCompletion(MediaPlayer mp) {
             Player.this.context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
             completion(context, list, position);
           }
         });
     playing = Config.PlayState.STATE_PLAYING;
     Player.this.context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
     return list.get(position);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Пример #10
0
 @Override
 public void pause() {
   super.pause();
   if (mediaPlayer != null) {
     mediaPlayer.reset();
   }
 }
Пример #11
0
 @Override
 public void onCompletion(MediaPlayer mp) {
   if (play.getCurrentPosition() > 0) {
     mp.reset();
     playNext();
   }
 }
Пример #12
0
 public void stop() {
   if (playing == Config.PlayState.STATE_PLAYING) {
     mediaPlayer.reset();
   }
   playing = Config.PlayState.STATE_STOP;
   Player.this.context.sendBroadcast(new Intent(Config.Broadcast.MUSIC_CHANGE));
 }
Пример #13
0
  public void payan() {
    if (MainActivity.sound) {
      if (mp_motevaset.isPlaying()) {
        mp_motevaset.stop();
        mp_motevaset.reset();
        mp_motevaset.release();
        mp_motevaset = null;
      }
    }
    // namayesh emtiaz va az sar giri
    int bestresult = pref.getInt("best_result_motevaset", 0);
    String bestresult_string = String.valueOf(bestresult);

    String emtiaz = String.valueOf(count);
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(500);
    // mire b activitie result va natijeha ra ha mibarad

    Intent result_intent = new Intent(getApplicationContext(), Result.class);
    Bundle extras = new Bundle();
    extras.putString("emtiaz", emtiaz);
    extras.putString("best_emtiaz", bestresult_string);
    extras.putString("level", "motevaset");
    result_intent.putExtras(extras);
    startActivity(result_intent);
    overridePendingTransition(R.anim.left, R.anim.abc_fade_out);
    onDestroy();
  }
Пример #14
0
  private void setSong() {
    if (mSongSelector.getCurrentSong() != null) {
      if (mPlayer == null) {
        createPlayer();
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      }
      mPlayer.reset();

      try {
        mPlayer.setDataSource(getApplicationContext(), mSongSelector.getCurrentSong().getUri());
      } 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();
      }
    }
  }
Пример #15
0
 private void prepareToStart(Track dataSource) {
   try {
     if (dataSource.isVideo()) {
       mediaController.setMediaPlayer(mVideoView);
       mVideoView.setVisibility(VideoView.VISIBLE);
       mVideoView.setVideoPath(dataSource.getPath());
       mVideoView.start();
     } else {
       mediaPlayer.reset();
       mVideoView.setVisibility(VideoView.INVISIBLE);
       mediaPlayer.setDataSource(dataSource.getPath());
       mediaPlayer.prepare();
       mediaPlayer.start();
     }
     ((TextView) findViewById(R.id.now_playing_text))
         .setText(currentPlaylist.getCurrent().getTitle());
   } catch (IllegalArgumentException e) {
     e.printStackTrace();
   } catch (SecurityException e) {
     e.printStackTrace();
   } catch (IllegalStateException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Пример #16
0
 private void tryToRestoreLocation() {
   try {
     if (location == null) {
       return;
     }
     boolean found = false;
     for (int i = 0; i < metaHolder.getSize(); i++) {
       if (metaHolder.get(i).getTitle().equals(location.title)) {
         currentPodcastInPlayer = i;
         found = true;
         break;
       }
     }
     if (!found) {
       location = null;
       return;
     }
     mediaPlayer.reset();
     mediaPlayer.setDataSource(currentFile().toString());
     mediaPlayer.prepare();
     mediaPlayer.seekTo(currentMeta().getCurrentPos());
     mediaMode = MediaMode.Paused;
   } catch (Throwable e) {
     // bummer.
   }
 }
Пример #17
0
  public boolean prepNextSong() {
    mp.reset();

    if (currentPlaylist.size() > 0) {
      currentTrack = currentPlaylist.get(globalTrackNo++);

      MySongManager.rebuildStats(this, currentTrack.getLocal_id());

      try {
        mp.setDataSource(currentTrack.getPath());
        mp.prepare();
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      }

      int i = Math.max(currentPlaylist.size() - 5, globalTrackNo);

      if (currentPlaylist.size() - 5 <= globalTrackNo) {
        // TODO async
        currentPlaylist.addAll(generateNewTracks(sessionType));
      }
      return true;
    } else {
      return false;
    }
  }
Пример #18
0
  public void setAudio(Uri audio, String name, Map<String, ?> extras) {
    if (audio == null) {
      throw new IllegalArgumentException("Audio URI may not be null.");
    }

    if (LOCAL_LOGV) {
      Log.v(TAG, "Changing audio source to " + audio);
    }

    if (mAudioPlayer != null) {
      mAudioPlayer.reset();
      mAudioPlayer.release();
      mAudioPlayer = null;
    }

    // Reset state variables
    mIsPrepared = false;
    mStartWhenPrepared = false;
    mSeekWhenPrepared = 0;
    mStopWhenPrepared = false;

    try {
      mAudioPlayer = new MediaPlayer();
      mAudioPlayer.setOnPreparedListener(mPreparedListener);
      mAudioPlayer.setDataSource(mContext, audio);
      mAudioPlayer.prepareAsync();
    } catch (IOException e) {
      Log.e(TAG, "Unexpected IOException.", e);
      mAudioPlayer.release();
      mAudioPlayer = null;
    }
    initAudioInfoView(name);
  }
Пример #19
0
        public void handleMessage(Message msg) {

          switch (msg.what) {
            case 1:
              if (hit == 0) {
                try {
                  if (alarmMusic.isPlaying()) {
                    alarmMusic.stop();
                    alarmMusic.reset();
                    alarmMusic.release();
                  }
                } catch (Exception e) {
                  alarmMusic = null;
                }
                mVibrator.cancel();
                // 恢复系统之前的音量
                mAudioManager.setStreamVolume(
                    AudioManager.STREAM_MUSIC, current, AudioManager.FLAG_PLAY_SOUND);
                AlarmActivity.this.finish();
                onStartService();
              } else {
                System.out.println("用户已经操作了");
              }
              break;
            case 0:
              mAudioManager.setStreamVolume(
                  AudioManager.STREAM_MUSIC, min + 1, AudioManager.FLAG_PLAY_SOUND);
              min += 1;
              System.out.println("min=" + min);
              break;

            default:
              break;
          }
        };
Пример #20
0
 @Override
 public void releaseMediaPlayerSync() {
   if (player != null) {
     player.reset();
     player = null;
   }
 }
 private void resetPlayer() {
   if (mMediaPlayer != null) {
     mMediaPlayer.reset();
     mMediaPlayer.release();
     mMediaPlayer = null;
   }
 }
 /**
  * メディアの停止.
  *
  * @param response レスポンス
  */
 public void stopMedia(final Intent response) {
   if (mSetMediaType == MEDIA_TYPE_MUSIC) {
     try {
       mMediaPlayer.stop();
       mMediaStatus = MEDIA_PLAYER_STOP;
       sendOnStatusChangeEvent("stop");
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
         mMediaPlayer.reset();
         putMediaId(null, mBackupMediaId);
       }
     } catch (IllegalStateException e) {
       if (BuildConfig.DEBUG) {
         e.printStackTrace();
       }
     }
     response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
     sendResponse(response);
   } else if (mSetMediaType == MEDIA_TYPE_VIDEO) {
     mMediaStatus = MEDIA_PLAYER_STOP;
     Intent mIntent = new Intent(VideoConst.SEND_HOSTDP_TO_VIDEOPLAYER);
     mIntent.putExtra(VideoConst.EXTRA_NAME, VideoConst.EXTRA_VALUE_VIDEO_PLAYER_STOP);
     getContext().sendBroadcast(mIntent);
     sendOnStatusChangeEvent("stop");
     response.putExtra(DConnectMessage.EXTRA_RESULT, DConnectMessage.RESULT_OK);
     sendResponse(response);
   }
 }
Пример #23
0
  /**
   * Plays the given sound, sets playAllListener if available on media player to start next sound
   */
  public static void playSound(String soundPath, OnCompletionListener playAllListener) {
    Log.i(
        AnkiDroidApp.TAG,
        "Playing " + soundPath + " has listener? " + Boolean.toString(playAllListener != null));

    if (soundPath.substring(0, 3).equals("tts")) {
      // TODO: give information about did
      //            ReadText.textToSpeech(soundPath.substring(4, soundPath.length()),
      //                    Integer.parseInt(soundPath.substring(3, 4)));
    } else {
      if (sMediaPlayer == null) sMediaPlayer = new MediaPlayer();
      else sMediaPlayer.reset();

      try {
        // soundPath is usually an URI, but Media player requires a path not url encoded
        URI soundURI = new URI(soundPath);
        soundPath = new File(soundURI).getAbsolutePath();
        sMediaPlayer.setDataSource(soundPath);
        sMediaPlayer.setVolume(AudioManager.STREAM_MUSIC, AudioManager.STREAM_MUSIC);
        sMediaPlayer.prepare();
        if (playAllListener != null) sMediaPlayer.setOnCompletionListener(playAllListener);

        sMediaPlayer.start();
      } catch (Exception e) {
        Log.e(
            AnkiDroidApp.TAG,
            "playSounds - Error reproducing sound " + soundPath + " = " + e.getMessage());
        releaseSound();
      }
    }
  }
Пример #24
0
 public void release(boolean paramBoolean) {
   if (mediaPlayer != null) {
     mediaPlayer.reset();
     mediaPlayer.release();
     mediaPlayer = null;
   }
 }
Пример #25
0
 /** reset */
 public void reset() {
   if (mmediaplayer != null) {
     mmediaplayer.reset();
   }
   mPlayStatus = VideoConst.PLAY_STATUS_UNKNOW;
   MmpTool.LOG_DBG("reset!");
 }
 @Override
 public void onCompletion(MediaPlayer mp) {
   // check if playback has reached the end of a track
   if (player.getCurrentPosition() > 0) {
     mp.reset();
     playNext();
   }
 }
 private void stopPlayback() {
   if (mMediaPlayer != null) {
     mMediaPlayer.stop();
     mMediaPlayer.reset();
     mMediaPlayer.release();
     mMediaPlayer = null;
   }
 }
Пример #28
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   mediaPlayer.reset();
   mediaPlayer.release();
   unregisterReceiver(receiver);
   handler.removeCallbacks(r);
 }
 public void stopPlay() {
   if (mCurRecordInfo == null) {
     return;
   }
   mMediaPlayer.stop();
   mMediaPlayer.reset();
   mCurRecordInfo.play = false;
 }
Пример #30
0
  /** manual preview */
  public void manualPrev() throws IllegalStateException {

    if (mmediaplayer != null) {
      if (mplayerMode == VideoConst.PLAYER_MODE_HTTP) {
        throw new IllegalStateException("Can't do Prev!!!");
      }

      if (videopl.getShuffleMode(Const.FILTER_VIDEO) == Const.SHUFFLE_ON
          || videopl.getRepeatMode(Const.FILTER_VIDEO) == Const.REPEAT_NONE) {
        if (videopl.getCurrentIndex(Const.FILTER_VIDEO) == 0) {
          throw new IllegalStateException("head of PlayList!!!");
        }
      }
      saveProgress(getProgress());
      if (mPlayStatus != VideoConst.PLAY_STATUS_STOPPED) {
        try {
          mmediaplayer.stop();
        } catch (IllegalStateException e) {
          e.printStackTrace();
          throw new IllegalStateException(e);
        }
        mPlayStatus = VideoConst.PLAY_STATUS_STOPPED;
      }

      mcurPath = videopl.getNext(Const.FILTER_VIDEO, Const.MANUALPRE);

      if (mcurPath == null) {
        MmpTool.LOG_DBG("End of PlayList!");
        stop();
      }

      MmpTool.LOG_DBG(mcurPath);

      mmediaplayer.reset();

      mPlayStatus = VideoConst.PLAY_STATUS_END;

      try {
        setDataSource(mcurPath);
      } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IllegalStateException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }

      try {
        play();
      } catch (IllegalStateException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }
    }
  }