Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #629 #631

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions app/src/main/java/io/neurolab/activities/MeditationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public final class MeditationActivity extends AppCompatActivity {

public static final String TAG = MeditationActivity.class.getCanonicalName(); // TAG for debugging purposes.
public static int MEDIA_RES_ID;
private static String KEY_PLAYER = "PlayerAdapter_Key";
private static String KEY_DURATIONVIEW = "DurationView_Key";

// Necessary view references.
private SeekBar seekbarAudio;
Expand All @@ -30,6 +32,7 @@ public final class MeditationActivity extends AppCompatActivity {

// the interface reference which would be used to control the media session from this UI client.
private PlayerAdapter playerAdapter;
private MediaPlayerHolder mediaPlayerHolder;

private boolean isUserSeeking = false;

Expand All @@ -41,24 +44,46 @@ protected void onCreate(Bundle savedInstanceState) {

MEDIA_RES_ID = getIntent().getIntExtra(MEDITATION_DIR_KEY, R.raw.soften_and_relax);

grabNecessaryReferencesAndSetListeners();
if (savedInstanceState == null) {
grabNecessaryReferencesAndSetListeners();

setTrackName(MEDIA_RES_ID);
setTrackName(MEDIA_RES_ID);

initializePlaybackController();
initializePlaybackController();

playerAdapter.loadMedia(MEDIA_RES_ID);
}
else {
grabNecessaryReferencesAndSetListeners();

setTrackName(MEDIA_RES_ID);

durationView.setText(savedInstanceState.getCharSequence(KEY_DURATIONVIEW));

mediaPlayerHolder = (MediaPlayerHolder)savedInstanceState.getSerializable(KEY_PLAYER);
mediaPlayerHolder.setPlaybackInfoListener(new PlaybackListener());
mediaPlayerHolder.initializeProgressCallback();

playerAdapter = mediaPlayerHolder;
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(KEY_PLAYER, mediaPlayerHolder);
outState.putCharSequence(KEY_DURATIONVIEW,durationView.getText());
}

@Override
protected void onStart() {
super.onStart();
playerAdapter.loadMedia(MEDIA_RES_ID);
}

@Override
protected void onStop() {
super.onStop();
// not releasing the media player resources during auto-rotation. I believe it won't make it logical for the user to listen to the audio again from the start if he rotates his phone.
if (isChangingConfigurations() && playerAdapter.isPlaying()) {
if (isChangingConfigurations()) {
Log.d(TAG, "onStop: don't release MediaPlayer as screen is rotating & playing");
} else {
playerAdapter.release();
Expand Down Expand Up @@ -114,7 +139,7 @@ private String getMeditationName(String rawName) {
}

private void initializePlaybackController() {
MediaPlayerHolder mediaPlayerHolder = new MediaPlayerHolder(this);
mediaPlayerHolder = new MediaPlayerHolder(this);
Log.d(TAG, "Inside initializePlaybackController method: MediaPlayerHolder Created");
mediaPlayerHolder.setPlaybackInfoListener(new PlaybackListener());
playerAdapter = mediaPlayerHolder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.neurolab.main.output.audio;

import java.io.Serializable;

// An Interface which allows the client Activity (containing the Media Controller UI) to control playback functions.
public interface PlayerAdapter {
public interface PlayerAdapter extends Serializable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkshobhyaP Why not Parceable and why even this change?


void loadMedia(int resourceId);

Expand Down