Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Copy code from the NumbersActivity and paste it into the NumbersFragment
/** 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();
}
};
@charlae4ive

This comment has been minimized.

Copy link

@charlae4ive charlae4ive commented Apr 6, 2017

Nice

@owolabiezekiel

This comment has been minimized.

Copy link

@owolabiezekiel owolabiezekiel commented Jun 7, 2017

can some one please share the new NumbersActivity.java file and the NumberFragments.java file?

@NicReg

This comment has been minimized.

Copy link

@NicReg NicReg commented Jun 22, 2017

Interesting the Fragment theme

@rebekaszucs

This comment has been minimized.

Copy link

@rebekaszucs rebekaszucs commented Jun 23, 2017

good content! making our app look even better!

@mezubeen

This comment has been minimized.

Copy link

@mezubeen mezubeen commented Jul 24, 2017

i am really excited :)

@mutabazigakuba

This comment has been minimized.

Copy link

@mutabazigakuba mutabazigakuba commented Oct 31, 2017

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?

@Sarvesh-Thiruppathi

This comment has been minimized.

Copy link

@Sarvesh-Thiruppathi Sarvesh-Thiruppathi commented Nov 16, 2017

@mezubeen me too!

@angwandi

This comment has been minimized.

Copy link

@angwandi angwandi commented Mar 26, 2018

The Code is pasted straight after the imports classes

@ID2GO

This comment has been minimized.

Copy link

@ID2GO ID2GO commented Apr 28, 2018

Thnx @angwandi, I thought as much

@Pijuvwy

This comment has been minimized.

Copy link

@Pijuvwy Pijuvwy commented May 12, 2018

Paste it after:

public class NumbersFragment extends Fragment {

And before:

public NumbersFragment() {
      // Required empty public constructor
}
@muhamadaliibrahim

This comment has been minimized.

Copy link

@muhamadaliibrahim muhamadaliibrahim commented Jul 26, 2018

دەستخۆش WELL DONE

@mixspark

This comment has been minimized.

Copy link

@mixspark mixspark commented Jan 18, 2019

very nice

@SayedMuhammed

This comment has been minimized.

Copy link

@SayedMuhammed SayedMuhammed commented Jan 21, 2019

done

@mixspark

This comment has been minimized.

Copy link

@mixspark mixspark commented Jan 22, 2019

ok

@alfredtally45

This comment has been minimized.

Copy link

@alfredtally45 alfredtally45 commented Oct 16, 2019

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);"

@xMagicXs

This comment has been minimized.

Copy link

@xMagicXs xMagicXs commented Oct 25, 2019

Paste it after:

public class NumbersFragment extends Fragment {

And before:

public NumbersFragment() {
      // Required empty public constructor
}

thank you :)

@FTW-Khushal

This comment has been minimized.

Copy link

@FTW-Khushal FTW-Khushal commented Feb 25, 2020

I was here

@emu-code

This comment has been minimized.

Copy link

@emu-code emu-code commented Oct 3, 2020

Great how this helps many more over the years

@SabalNiroula

This comment has been minimized.

Copy link

@SabalNiroula SabalNiroula commented Oct 11, 2020

@SabalNiroula

This comment has been minimized.

Copy link

@SabalNiroula SabalNiroula commented Oct 11, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment