Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:52:43+00:00 2026-06-11T19:52:43+00:00

I am using Audio track to play a different sounds, in stream mode. I

  • 0

I am using Audio track to play a different sounds, in stream mode.
I would like to know if there is a way to know when each sound beings/ends playing.

I create the audio track like this:

AudioTrack tmpAudioTrack = new AudioTrack(
        STREAM_TYPE, 
        SAMPLE_RATE, 
        CHANNEL_CONFIG_TYPE, 
            AUDIO_FORMAT_TYPE, 
        getOptimalBufferSize(), 
        AUDIO_TRACK_MODE);'

And start it in a background thread:

backround_thread = new Thread(new MyRunnable(aTrack));
    backround_thread.start();   

I write each sound like this inside the runnable:

byte generatedSnd[] = new byte[2 * beepSamples];
<code for filling the buffer with sound here>
int bytesWritten = track.write(generatedSnd, 0, generatedSnd.length);

It is possible to use any of the AudioTrack APIs such setNotificationMarkerPosition, or setLoopPoints, or setPositionNotificationPeriod to accomplish this? and how do they work?

Each sound can be different duration of time. I think this is key.

I don’t fully understand the documentation for these APIs. Is each frame the same as a sample? How do I specify a marker for where each sound begin/end?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:52:45+00:00Added an answer on June 11, 2026 at 7:52 pm

    This is what I have found out:

    To me, frames are samples — the duration of the sound multiplied times the sample rate.

    To use AudioTrack.setPositionNotificationPeriod, you pass an amount of samples. Meaning if you pass 200 samples, the callback will be called every 200 samples, recurrent.

    tmpAudioTrack.setPositionNotificationPeriod(duration * sampleRate);
    

    To use .setNotificationMarkerPosition, you also pass an amount of samples. However, this is absolute and not relative like for the period API. So if you want to determine when a sound ends, you pass the sample amount (total sound track duration * sampleRate).

    tmpAudioTrack.setNotificationMarkerPosition(duration * sampleRate);
    

    But, if you are already playing, in the middle of your sound track, and want to add a marker so you will get called back let’s say 3 seconds from now, then you would need to add the current playhead of the audio track, like this: (where your duration is 3 seconds)

    tmpAudioTrack.setNotificationMarkerPosition(tmpAudioTrack.getPlaybackHeadPosition() + (duration * sampleRate));
    

    And this is how you get registered for the period and marker notifications:

    tmpAudioTrack.setPlaybackPositionUpdateListener(new OnPlaybackPositionUpdateListener(){
    
        @Override
        public void onMarkerReached(AudioTrack arg0) {
    
        }
    
        @Override
        public void onPeriodicNotification(AudioTrack arg0) {
    
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
Is there a way using Core Audio on OS X to extract a set
I want to play back WAV sound (audio track of some custom video format)
Currently I'm using AudioTrack passing to it audio data from native layer to play.
I want to capture and stream audio using JMF 2.1.1e in RTP format. I
I'd like to take a set of images and a sound track and use
I am using MPMoviePlayerController to play streaming audio. I'm trying to get background audio
When playing a sound using e.g: sound(x,fs); I sometimes by accident play the wrong
I'm using opencv (for object recognition) combined with portaudio to play sounds based on
I'm trying to play an HTML5 audio track a few seconds after the page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.