Java 类android.media.MediaPlayer 实例源码

项目:ParsingPlayer    文件:ParsingPlayerProxy.java   
private String errToStr(int framework_err, int impl_err) {
    String msg = null;
    if (framework_err == MediaPlayer.MEDIA_ERROR_IO) {
        msg = "IO Error";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_MALFORMED) {
        msg = "Bitstream unsupported";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK) {
        msg = "Invalid progressive playback";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
        msg = "Operation time out";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
        msg = "MediaPlayer died";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_UNSUPPORTED) {
        msg = "File spec is not supported in the media framework";
    } else if (framework_err == MediaPlayer.MEDIA_ERROR_UNKNOWN) {
        msg = "Unknown error";
    }
    return msg;
}
项目:letv    文件:RedPacketDialog.java   
private void soundShake() {
    try {
        this.mPlayer = MediaPlayer.create(RedPacketSdkManager.getInstance().getApplicationContext(), R.raw.shake_sound);
        if (this.mPlayer != null) {
            this.mPlayer.start();
            this.mPlayer.setOnCompletionListener(new OnCompletionListener() {
                public void onCompletion(MediaPlayer mp) {
                    RedPacketDialog.this.mPlayer.release();
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (this.mPlayer != null) {
            this.mPlayer.release();
        }
    }
}
项目:react-native-videoplayer    文件:ReactVideoView.java   
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
    switch (what) {
        case MediaPlayer.MEDIA_INFO_BUFFERING_START:
            mEventEmitter.receiveEvent(getId(), Events.EVENT_STALLED.toString(), Arguments.createMap());
            break;
        case MediaPlayer.MEDIA_INFO_BUFFERING_END:
            mEventEmitter.receiveEvent(getId(), Events.EVENT_RESUME.toString(), Arguments.createMap());
            break;
        case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
            mEventEmitter.receiveEvent(getId(), Events.EVENT_READY_FOR_DISPLAY.toString(), Arguments.createMap());
            break;

        default:
    }
    return false;
}
项目:youtube_background_android    文件:DownloadedFragment.java   
@Override
    public void onPrepared(MediaPlayer mp) {
        if(mHasVideo) {
            mediaPlayer.start();
            mediaPlayer.setVolume(0,0);
            setVideoSize();
            vidSurface.bringToFront();
            vidSurface.requestFocus();
            MediaController mController = new MediaController(context);
            mController.setMediaPlayer(this);
            mController.setAnchorView(vidSurface);

//        mController.show(0);
            vidSurface.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    return true;
                }
            });
        }
    }
项目:lokey    文件:IME.java   
private void initializeMedia() {
    mediaEight[0] = MediaPlayer.create(getApplicationContext(), R.raw.eight_1);
    mediaEight[1] = MediaPlayer.create(getApplicationContext(), R.raw.eight_2);
    mediaEight[2] = MediaPlayer.create(getApplicationContext(), R.raw.eight_3);
    mediaEight[3] = MediaPlayer.create(getApplicationContext(), R.raw.eight_4);
    mediaEight[4] = MediaPlayer.create(getApplicationContext(), R.raw.eight_5);
    mediaEight[5] = MediaPlayer.create(getApplicationContext(), R.raw.eight_7);
    mediaEight[6] = MediaPlayer.create(getApplicationContext(), R.raw.eight_8);

    mediaEight[0].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[1].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[2].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[3].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[4].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[5].setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaEight[6].setAudioStreamType(AudioManager.STREAM_MUSIC);
}
项目:Logistics-guard    文件:MessageFragment.java   
private void playRecord() throws IOException {

        File dir = new File(Environment.getExternalStorageDirectory() + File.separator + "AAAAAAAAA");
        if (dir.exists()) {
            File[] files = dir.listFiles();
            if (files.length > 0) {
                mediaPlayer.setDataSource(files[0].getAbsolutePath());
                mediaPlayer.prepare();
                mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mp) {
                        mediaPlayer.start();
                    }
                });
            }
        }
    }
项目:AndroidTvDemo    文件:AndroidMediaPlayer.java   
public AndroidMediaPlayer() {
    synchronized (mInitLock) {
        mInternalMediaPlayer = new MediaPlayer();
    }
    mInternalMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mInternalListenerAdapter = new AndroidMediaPlayerListenerHolder(this);
    attachInternalListeners();
}
项目:react-native-sound-player    文件:RNSoundPlayerModule.java   
@ReactMethod
public void playSoundFile(String name, String type) throws IOException {
  if (this.mediaPlayer == null) {
    int soundResID = getReactApplicationContext().getResources().getIdentifier(name, "raw", getReactApplicationContext().getPackageName());
    this.mediaPlayer = MediaPlayer.create(getCurrentActivity(), soundResID);
    this.mediaPlayer.setOnCompletionListener(
      new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer arg0) {
          WritableMap params = Arguments.createMap();
          params.putBoolean("success", true);
          sendEvent(getReactApplicationContext(), "FinishedPlaying", params);
        }
    });
  } else {
    Uri uri = Uri.parse("android.resource://" + getReactApplicationContext().getPackageName() + "/raw/" + name);
    this.mediaPlayer.reset();
    this.mediaPlayer.setDataSource(getCurrentActivity(), uri);
    this.mediaPlayer.prepare();
  }
  this.mediaPlayer.start();
}
项目:SmartButler    文件:BeepManager.java   
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
项目:Android-Bubble-Game    文件:GamePanel.java   
public static void chimeSound() {
  ((Activity) MainMenu.getAppContext()).runOnUiThread(new Runnable() {
    public void run() {
      final MediaPlayer mp1 = MediaPlayer.create(MainMenu.getAppContext(), R.raw.chime);
      mp1.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
          mp1.release();
        }

      });
      mp1.start();
    }
  });
}
项目:DroidStreamingDemo    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //initializing button
    btn = findViewById(R.id.play);

    //initializing mediaPlayer object
    mediaPlayer = new MediaPlayer();

    //setting streaming type
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    //setting clickListener on button
    btn.setOnClickListener(pausePlay);

}
项目:TestChat    文件:ImageDisplayActivity.java   
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
        switch (what) {
                case MediaPlayer.MEDIA_INFO_BAD_INTERLEAVING:
                        // 音频和视频数据不正确
                        break;
                case MediaPlayer.MEDIA_INFO_BUFFERING_START:
                        if (!isFinishing())
                                mSurfaceVideoView.pause();
                        break;
                case MediaPlayer.MEDIA_INFO_BUFFERING_END:
                        if (!isFinishing())
                                mSurfaceVideoView.start();
                        break;
                case MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
                        if (DeviceUtils.hasJellyBean()) {
                                mSurfaceVideoView.setBackground(null);
                        } else {
                                mSurfaceVideoView.setBackgroundDrawable(null);
                        }
                        break;
        }
        return false;
}
项目:VideoWallPager    文件:VideoLiveWallPaper.java   
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
    super.onSurfaceCreated(holder);
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setSurface(holder.getSurface());
    try {
        AssetManager assets = getApplicationContext().getAssets();
        AssetFileDescriptor descriptor = assets.openFd("text1.mp4");
        mMediaPlayer.setDataSource(descriptor.getFileDescriptor(),descriptor.getStartOffset(),descriptor.getLength());
        mMediaPlayer.setLooping(true);
        mMediaPlayer.setVolume(1.0f,1.0f);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:TripBuyer    文件:LCIMAudioHelper.java   
/**
 * 播放语音文件
 *
 * @param path
 * @param finishCallback
 */
public synchronized void playAudio(String path, Runnable finishCallback) {
  if (onceStart) {
    mediaPlayer.reset();
  }
  tryRunFinishCallback();
  audioPath = path;
  LCIMAudioHelper.this.finishCallback = finishCallback;
  try {
    mediaPlayer.setDataSource(path);
    mediaPlayer.prepare();
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
      @Override
      public void onCompletion(MediaPlayer mp) {
        tryRunFinishCallback();
      }
    });
    mediaPlayer.start();
    onceStart = true;
  } catch (IOException e) {
  }
}
项目:QRScanner    文件:BeepManager.java   
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
项目:MyFire    文件:BeepManager.java   
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
项目:AI-Powered-Intelligent-Banking-Platform    文件:AlexaAudioPlayer.java   
@Override
public void onCompletion(MediaPlayer mp) {
    for(Callback callback: mCallbacks){
        callback.playerProgress(mItem, 1, 1);
        callback.itemComplete(mItem);
    }
}
项目:BookReader-master    文件:TypeTextView.java   
private void playAudio(int audioResId) {
    try {
        stopAudio();
        mMediaPlayer = MediaPlayer.create(mContext, audioResId);
        mMediaPlayer.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:react-native-videoplayer    文件:FullscreenPlayer.java   
@Override
    public void onCompletion(MediaPlayer mp) {
//        this.complete();
        if(this.tinyPlayer!=null){
            tinyPlayer.complete();
            tinyPlayer.exitFullscreen();
        }

//        super.onCompletion(mp);
    }
项目:Android-AudioRecorder-App    文件:PlayListFragment.java   
@Override public void startMediaPlayer(int position, RecordingItem recordingItem)
    throws IOException {
  mMediaPlayer = new MediaPlayer();
  mMediaPlayer.setDataSource(recordingItem.getFilePath());
  mMediaPlayer.prepare();
  mMediaPlayer.setOnPreparedListener(MediaPlayer::start);
  mMediaPlayer.setOnCompletionListener(mp -> playListPresenter.mediaPlayerStopped());
  Log.i("Debug ", "Started");
}
项目:LucaHome-AndroidApplication    文件:CenterViewController.java   
private void initializeMediaPlayer() {
    _radioPlayer = new MediaPlayer();

    try {
        _radioPlayer.setDataSource(_radioStream.GetUrl());
    } catch (Exception e) {
        Logger.getInstance().Error(TAG, e.getMessage());
        Toasty.error(_context, "An error appeared settings url for radio player!", Toast.LENGTH_LONG).show();
    }

    _radioPlayer.setOnBufferingUpdateListener((mediaPlayer, percent) -> Logger.getInstance().Information(TAG, String.format(Locale.getDefault(), "Buffered to %d%%", percent)));
    _radioPlayer.setOnPreparedListener(mediaPlayer -> _radioPlayer.start());
}
项目:Hello-Music-droid    文件:MusicService.java   
@Override
public void onCompletion(final MediaPlayer mp) {
    if (mp == mCurrentMediaPlayer && mNextMediaPlayer != null) {
        mCurrentMediaPlayer.release();
        mCurrentMediaPlayer = mNextMediaPlayer;
        mNextMediaPath = null;
        mNextMediaPlayer = null;
        mHandler.sendEmptyMessage(TRACK_WENT_TO_NEXT);
    } else {
        mService.get().mWakeLock.acquire(30000);
        mHandler.sendEmptyMessage(TRACK_ENDED);
        mHandler.sendEmptyMessage(RELEASE_WAKELOCK);
    }
}
项目:alpha-movie    文件:AlphaMovieView.java   
private void prepareAsync(final MediaPlayer.OnPreparedListener onPreparedListener) {
    if (mediaPlayer != null && state == PlayerState.NOT_PREPARED
            || state == PlayerState.STOPPED) {
        mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                state = PlayerState.PREPARED;
                onPreparedListener.onPrepared(mp);
            }
        });
        mediaPlayer.prepareAsync();
    }
}
项目:GravityBox    文件:QuickRecordTile.java   
private void startPlaying() {
    mPlayer = new MediaPlayer();
    try {
        mPlayer.setDataSource(mAudioFileName);
        mPlayer.prepare();
        mPlayer.start();
        mRecordingState = STATE_PLAYING;
        refreshState();
        mPlayer.setOnCompletionListener(stoppedPlaying);
    } catch (IOException e) {
        log(getKey() + ": startPlaying failed: " + e.getMessage());
    }
}
项目:PicShow-zhaipin    文件:JCVideoPlayer.java   
public void onInfo(int what, int extra) {
    Log.d(TAG, "onInfo what - " + what + " extra - " + extra);
    if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
        BACKUP_PLAYING_BUFFERING_STATE = currentState;
        setUiWitStateAndScreen(CURRENT_STATE_PLAYING_BUFFERING_START);//没这个case
        Log.d(TAG, "MEDIA_INFO_BUFFERING_START");
    } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
        if (BACKUP_PLAYING_BUFFERING_STATE != -1) {
            setUiWitStateAndScreen(BACKUP_PLAYING_BUFFERING_STATE);
            BACKUP_PLAYING_BUFFERING_STATE = -1;
        }
        Log.d(TAG, "MEDIA_INFO_BUFFERING_END");
    }
}
项目:HeadlineNews    文件:JCMediaManager.java   
@Override
public void onCompletion(MediaPlayer mp) {
    mainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            if (JCVideoPlayerManager.getCurrentJcvd() != null) {
                JCVideoPlayerManager.getCurrentJcvd().onAutoCompletion();
            }
        }
    });
}
项目:Quran    文件:AudioService.java   
@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
  Timber.d("seek complete! %d vs %d",
      mediaPlayer.getCurrentPosition(), mPlayer.getCurrentPosition());
  mPlayer.start();
  mHandler.sendEmptyMessageDelayed(MSG_UPDATE_AUDIO_POS, 200);
}
项目:YZxing    文件:BeepManager.java   
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
    if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
        // we are finished, so put up an appropriate error toast if required and finish
        activity.finish();
    } else {
        // possibly media player error, so release and recreate
        close();
        updatePrefs();
    }
    return true;
}
项目:CCDownload    文件:ADMediaPlayActivity.java   
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
    Message msg = new Message();
    msg.what = what;
    if (alertHandler != null) {
        alertHandler.sendMessage(msg);
    }
    return false;
}
项目:letv    文件:VideoViewH264m3u8Hw_4D.java   
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    VideoViewH264m3u8Hw_4D.this.mVideoWidth = mp.getVideoWidth();
    VideoViewH264m3u8Hw_4D.this.mVideoHeight = mp.getVideoHeight();
    if (!(VideoViewH264m3u8Hw_4D.this.mVideoWidth == 0 || VideoViewH264m3u8Hw_4D.this.mVideoHeight == 0)) {
        VideoViewH264m3u8Hw_4D.this.getHolder().setFixedSize(VideoViewH264m3u8Hw_4D.this.mVideoWidth, VideoViewH264m3u8Hw_4D.this.mVideoHeight);
    }
    if (VideoViewH264m3u8Hw_4D.this.mOnVideoSizeChangedListener != null) {
        VideoViewH264m3u8Hw_4D.this.mOnVideoSizeChangedListener.onVideoSizeChanged(mp, VideoViewH264m3u8Hw_4D.this.mVideoWidth, VideoViewH264m3u8Hw_4D.this.mVideoHeight);
    }
}
项目:AssistantBySDK    文件:VoiceInputComponent.java   
/**
 * 构造函数
 */
public SpeechPlayer() {
    mPlayer = new MediaPlayer();
    timer = new Timer(true);
    mAssetManager = context.getAssets();
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnCompletionListener(this);
}
项目:Underlined    文件:SoundManager.java   
public static void turnSoundOn() {
    isSoundOn = true;
    if(isplayingAudio){
        mediaPlayer = MediaPlayer.create(context, lastSound);
        mediaPlayer.start();
    }
}
项目:2017.2-codigo    文件:MusicPlayerWithBindingService.java   
@Override
public void onCreate() {
    super.onCreate();

    // configurar media player
    mPlayer = MediaPlayer.create(this, R.raw.moonlightsonata);

    if (null != mPlayer) {
        //fica em loop
        mPlayer.setLooping(true);
    }


    // cria notificacao na area de notificacoes para usuario voltar p/ Activity
    final Intent notificationIntent = new Intent(getApplicationContext(), MusicPlayerWithBindingActivity.class);
    final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    final Notification notification = new Notification.Builder(
            getApplicationContext())
            .setSmallIcon(android.R.drawable.ic_media_play)
            .setOngoing(true).setContentTitle("Music Service rodando")
            .setContentText("Clique para acessar o player!")
            .setContentIntent(pendingIntent).build();

    // inicia em estado foreground, para ter prioridade na memoria
    // evita que seja facilmente eliminado pelo sistema
    startForeground(NOTIFICATION_ID, notification);
}
项目:Things-Audio-Renderer    文件:PlayerService.java   
@Override
public void onCreate() {
    super.onCreate();
    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);


    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Constants.BA_NEW_TRACKLIST);
    intentFilter.addAction(Constants.BA_SKIP_NEXT);
    intentFilter.addAction(Constants.BA_SKIP_PREV);
    intentFilter.addAction(Constants.BA_PAUSE);
    intentFilter.addAction(Constants.BA_PLAY);
    registerReceiver(controlReceiver, intentFilter);

    progressDisposable = Observable.interval(1, TimeUnit.SECONDS).map(aLong -> mediaPlayer.getCurrentPosition() / 1000)
            .distinctUntilChanged()
            .subscribe(integer -> {
                PlayPosition playPosition = new PlayPosition();
                playPosition.setPosition(integer);
                Intent posInt = new Intent();
                posInt.putExtra(Constants.BK_PLAYBACKEVENT, playPosition);
                posInt.setAction(Constants.BA_PLAYBACKEVENT);

                sendBroadcast(posInt);
                Log.d("Player", "pos" + integer);
            });
}
项目:android-PictureInPicture    文件:MovieView.java   
void openVideo(Surface surface) {
    if (mVideoResourceId == 0) {
        return;
    }
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setSurface(surface);
    startVideo();
}
项目:QrCode    文件:BeepManager.java   
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
  if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
    // we are finished, so put up an appropriate error toast if required and finish
    activity.finish();
  } else {
    // possibly media player error, so release and recreate
    close();
    updatePrefs();
  }
  return true;
}
项目:Discover    文件:JZMediaSystem.java   
@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
    JZMediaManager.instance().mainThreadHandler.post(new Runnable() {
        @Override
        public void run() {
            if (JZVideoPlayerManager.getCurrentJzvd() != null) {
                JZVideoPlayerManager.getCurrentJzvd().onSeekComplete();
            }
        }
    });
}
项目:Quran    文件:AudioService.java   
/** Called when media player is done preparing. */
@Override
public void onPrepared(MediaPlayer player) {
  Timber.d("okay, prepared!");

  // The media player is done preparing. That means we can start playing!
  mState = State.Playing;
  if (mShouldStop) {
    processStopRequest();
    mShouldStop = false;
    return;
  }

  // if gapless and sura changed, get the new data
  if (mAudioRequest.isGapless()) {
    if (mGaplessSura != mAudioRequest.getCurrentSura()) {
      if (mTimingTask != null) {
        mTimingTask.cancel(true);
      }

      String dbPath = mAudioRequest.getGaplessDatabaseFilePath();
      mTimingTask = new ReadGaplessDataTask(dbPath);
      mTimingTask.execute(mAudioRequest.getCurrentSura());
    }
  }

  if (mPlayerOverride || !mAudioRequest.isGapless()) {
    notifyAyahChanged();
  }

  updateNotification();
  configAndStartMediaPlayer();
}
项目:Espresso    文件:BeepManager.java   
@Override
public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
    if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
        // we are finished, so put up an appropriate error toast if required
        // and finish
        activity.finish();
    } else {
        // possibly media player error, so release and recreate
        mp.release();
        mediaPlayer = null;
        updatePrefs();
    }
    return true;
}
项目:ThunderMusic    文件:MediaPlaybackService.java   
public void setDataSource(String path) {
    try {
        mOnlineDuration = 0;
        mCurrentMediaPlayer.reset();
        if (path.startsWith("content://")) {
            mCurrentMediaPlayer.setDataSource(
                    MediaPlaybackService.this, Uri.parse(path));
        } else {
            mCurrentMediaPlayer.setDataSource(path);
        }
        mCurrentMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

        mCurrentMediaPlayer.prepareAsync();
        mCurrentMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                mOnlineDuration = mCurrentMediaPlayer.getDuration();
                mp.setOnCompletionListener(listener);
                mp.setOnErrorListener(errorListener);
                setOnInfoListener();

                Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
                i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
                i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
                sendBroadcast(i);
                mIsInitialized = true;
                notifyChange(META_CHANGED);
                notifyChange(END_BUFFERING);
            }
        });
    } catch (IOException ex) {
        mIsInitialized = false;
        return;
    }
}