-
-
Save udacityandroid/3a2fdbf1e487a292d199bebe51c2d4e6 to your computer and use it in GitHub Desktop.
/** Handles playback of all the sound files */ | |
private MediaPlayer mMediaPlayer; | |
/** Handles audio focus when playing a sound file */ | |
private AudioManager mAudioManager; | |
/** | |
* This listener gets triggered whenever the audio focus changes | |
* (i.e., we gain or lose audio focus because of another app or device). | |
*/ | |
private AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() { | |
@Override | |
public void onAudioFocusChange(int focusChange) { | |
if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || | |
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) { | |
// The AUDIOFOCUS_LOSS_TRANSIENT case means that we've lost audio focus for a | |
// short amount of time. The AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK case means that | |
// our app is allowed to continue playing sound but at a lower volume. We'll treat | |
// both cases the same way because our app is playing short sound files. | |
// Pause playback and reset player to the start of the file. That way, we can | |
// play the word from the beginning when we resume playback. | |
mMediaPlayer.pause(); | |
mMediaPlayer.seekTo(0); | |
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { | |
// The AUDIOFOCUS_GAIN case means we have regained focus and can resume playback. | |
mMediaPlayer.start(); | |
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) { | |
// The AUDIOFOCUS_LOSS case means we've lost audio focus and | |
// Stop playback and clean up resources | |
releaseMediaPlayer(); | |
} | |
} | |
}; | |
/** | |
* This listener gets triggered when the {@link MediaPlayer} has completed | |
* playing the audio file. | |
*/ | |
private MediaPlayer.OnCompletionListener mCompletionListener = new MediaPlayer.OnCompletionListener() { | |
@Override | |
public void onCompletion(MediaPlayer mediaPlayer) { | |
// Now that the sound file has finished playing, release the media player resources. | |
releaseMediaPlayer(); | |
} | |
}; |
can some one please share the new NumbersActivity.java file and the NumberFragments.java file?
NumberFragments.java can be found here :) https://github.com/udacity/ud839_Miwok/blob/d7effcef3bf7fdccdd045c974d67abd5b960fae7/app/src/main/java/com/example/android/miwok/NumbersFragment.java
Interesting the Fragment theme
good content! making our app look even better!
i am really excited :)
Where do we exactly paste the codes above?
Do we delete all codes from the fragment java file or ? I didnt understand where to paste the codes?
Help?
@mezubeen me too!
The Code is pasted straight after the imports classes
Thnx @angwandi, I thought as much
Paste it after:
public class NumbersFragment extends Fragment {
And before:
public NumbersFragment() {
// Required empty public constructor
}
دەستخۆش WELL DONE
very nice
done
ok
NumberFragments.java can be found here :) https://github.com/udacity/ud839_Miwok/blob/d7effcef3bf7fdccdd045c974d67abd5b960fae7/app/src/main/java/com/example/android/miwok/NumbersFragment.java
@evii
Thanks very much for the code
you referecnecd category_numbers but cannot be found in the colors directory,please help
"WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_numbers);"
Paste it after:
public class NumbersFragment extends Fragment {
And before:
public NumbersFragment() { // Required empty public constructor }
thank you :)
I was here
Great how this helps many more over the years
NumberFragments.java can be found here :) https://github.com/udacity/ud839_Miwok/blob/d7effcef3bf7fdccdd045c974d67abd5b960fae7/app/src/main/java/com/example/android/miwok/NumbersFragment.java
Great how this helps many more over the years
many
NumberFragments.java can be found here :) https://github.com/udacity/ud839_Miwok/blob/d7effcef3bf7fdccdd045c974d67abd5b960fae7/app/src/main/java/com/example/android/miwok/NumbersFragment.java
Great how this helps many more over the years
many years
I am getting null pointer exception on adapter reference of WordAdapter class which we created when calling method ListView.setAdapter
WordAdapter itemsAdapter = new WordAdapter(getActivity(), words, R.color.category_numbers);
//ListView listView = findViewById(R.id.list);
ListView listView = (ListView) rootView.findViewById(R.id.list);
listView.setAdapter(itemsAdapter);
Nice