@Override public void onDestroy() { if (null != mPlayer) { // Stop player cancelPlaybackNotification(); mPlayer.mShouldRun = false; mPlayer.interrupt(); mPlayer = null; } if (null != mUploader) { mUploader.stop(); mUploader = null; } }
@Override public void onCreate() { if (null == mPlayer) { mPlayer = new BooPlayer(this, this); mPlayer.start(); // Initialize player. Boo boo = Boo.constructFromFile(getStateFilename()); if (null == boo) { boo = Boo.createIntroBoo(this); } mPlayer.play(boo, false); } if (null == mUploader) { mUploader = new UploadManager(this); } }
public void play(BooData boo, boolean playImmediately) { Boo b = new Boo(boo); // FIXME b.writeToFile(getStateFilename()); // Mark boo as read, if it's a message. if (b.mData.mIsMessage) { // Ignore results. Globals.get().mAPI.markRead(b, new Handler()); } mPlayer.play(b, playImmediately); }
private void showPlaybackNotification() { PlayerState state = mPlayer.getPlayerState(); if (null == state) { return; } // Create notification NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // Create intent for notification clicks. We want to open the Boo's detail // view. Intent intent = new Intent( Intent.ACTION_VIEW, UriUtils.createDetailsUri(state.mBooId, state.mBooIsMessage)); PendingIntent contentIntent = PendingIntent.getActivity(AudiobooService.this, 0, intent, 0); // Create Notification Resources res = getResources(); String title = (null != state.mBooTitle) ? state.mBooTitle : res.getString(R.string.notification_default_title); String username = (null != state.mBooUsername) ? state.mBooUsername : res.getString(R.string.notification_unknown_user); String text = String.format(res.getString(R.string.notification_text), username); Notification notification = new Notification(R.drawable.notification, null, System.currentTimeMillis()); notification.setLatestEventInfo(AudiobooService.this, title, text, contentIntent); // Set ongoing and no-clear flags to ensure the notification stays until // cleared by this service. notification.flags |= Notification.FLAG_ONGOING_EVENT; notification.flags |= Notification.FLAG_NO_CLEAR; // Install notification nm.notify(Constants.NOTIFICATION_PLAYING_BACK, notification); }
public PlayerState getState() { return mPlayer.getPlayerState(); }
public void seekTo(double position) { mPlayer.seekTo(position); }
public void resume() { mPlayer.resumePlaying(); }
public void pause() { mPlayer.pausePlaying(); cancelPlaybackNotification(); }
public void stop() { mPlayer.stopPlaying(); cancelPlaybackNotification(); }