1

In the following class the playback of the .ogg file is triggered.

public class HomeScreenFragment extends Fragment {
    ...
    private AudioPlayer mPlayer = new AudioPlayer();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        ...
        mStandbyButton = (Button)v.findViewById(R.id.standby_button);
        mStandbyButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mPlayer.play(getActivity());
            }
        });
    }

    public void onDestroy() {
        super.onDestroy();
        mPlayer.stop();
    }
}

Despite of using the setOnCompletionListener() the files keep on looping unlike .wav

public class AudioPlayer {
    private MediaPlayer mPlayer;

    public void stop() {
        if(mPlayer != null) {
            mPlayer.release();
            mPlayer = null;
        }
    }

    public void play(Context c) {
        stop();

        mPlayer = MediaPlayer.create(c, R.raw.hassium);
        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                stop();
            }
        });
        mPlayer.start();
    }
}

How to ensure they don't loop once playback is completed? I could possibly work with .wav files but curious as to why this happens and if possible prevent them from looping.

Ashish
  • 85
  • 1
  • 8

1 Answers1

1

Searching shows that there may be ANDROID_LOOP in ogg metadata: ANDROID_LOOP = true -- how to avoid MediaPlayer looping audios with this metadata tag

Related tickets in Google Code:

MediaPlayer setLooping(false) does not work for ogg files

Should document ANDROID_LOOP flag for OGG files

You can try to use MediaPlayer.setLooping(false) to see if it can help

Community
  • 1
  • 1
Mixaz
  • 4,068
  • 1
  • 29
  • 55
  • It seems the metadata tag ANDROID_LOOP in the ogg files are responsible for the behavior. Also MediaPlayer.setLooping(false) doesn't override this behavior. So the only option would be to edit the ogg files. If anyone is interested you can check [this](http://www.tytyweb.net/blog/2012/01/looping-ringtones-on-android/) out. Edit:Added links – Ashish Nov 15 '14 at 05:32