audiotrack

AudioTrack: how to detect end of sound?

*爱你&永不变心* 提交于 2019-12-22 18:46:09
问题 I'm using AudioTrack to play a PCM WAV sound file on Android (see also here). Streaming mode, worker thread. I'm wondering how do I detect the end of sound so that I can release and free the AudioTrack . The write() call, it seems, is blocking - but does it block until the playback of the provided data is complete? Not so sure. Is it me, or the docs on this class are woefully inadequate? If you happen to have a link to a nice unofficial guide to AudioTrack , I'd be willing to see one. 回答1:

Cannot stop AudioTrack on Android 5

时光怂恿深爱的人放手 提交于 2019-12-22 00:33:12
问题 I cannot stop playback of an AudioTrack on a Nexus 4 running Android 5.0.1. Am I doing something wrong? The code is very simple (it's actually just a test app) and it works perfectly on devices running 2.3.6 and 4.4. Here's the relevant portion: mPlugReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if(Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) { boolean plugged = intent.getIntExtra("state", 0) == 1; if(plugged) { log.debug(

using Android's AudioTrack to combine bytes of sound samples produces noise

大憨熊 提交于 2019-12-18 17:53:04
问题 I'm building a fairly simple Android app (sdk revision 14: ICS) which allows users to pick two audio clips at a time (all are RIFF/WAV format, little-endian, signed PCM-16 bit encoding) and combine them in various ways to create new sounds. The most basic method I'm using for this combination is as follows: //...sound samples are read in to memory as raw byte arrays elsewhere //...offset is currently set to 45 so as to skip the 44 byte header of basic //RIFF/WAV files ... //Actual combination

Android audio programming nightmare - soundpool, audiotrack arrghh?

风格不统一 提交于 2019-12-18 16:13:18
问题 I've built a simple music sequencer Android app that plays multiple audio files. Originally I was using SoundPool to play mp3 files and it worked perfectly on 2.3.4 with an old HTC Droid Incredible. Then I tested it on a Galaxy Nexus running 4.3 and the performance was horrendous. The audio timing all over the place and there were glitches/clicks/pops. So I spent several days making a player using AudioTrack including an mp3 decoder and got it working perfectly on both the Galaxy and the HTC.

SoundPool error: no more track names available

耗尽温柔 提交于 2019-12-18 12:56:11
问题 I'm having troubles with the soundpool class. Here it goes: In my game app (music app btw) I need to reproduce at least 32 short sounds at the same time, so I declare my soundpool like that: private SoundPool sp; sp = new SoundPool(128, AudioManager.STREAM_MUSIC, 0); After that I load all the MP3 sounds needed, about 80 sound of 55KB each. I have no troubles loading all the sounds, but its slow! Well it's no the problem. The real trouble is when I play about 20 sounds at the same time, there

Play sound in left or right speaker using android AudioTrack

不打扰是莪最后的温柔 提交于 2019-12-18 07:23:26
问题 I am playing sound with the help of AudioTrack in my APP but i want to play sound in specific speaker/ear means left speaker or right speaker or both speaker. Following code i am using to play sound. private AudioTrack generateTone(double freqHz, int durationMs) { int count = (int)(44100.0 * 2.0 * (durationMs / 1000.0)) & ~1; short[] samples = new short[count]; for(int i = 0; i < count; i += 2){ short sample = (short)(Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF); samples[i + 0] =

AudioTrack Android playing sounds from raw folder

妖精的绣舞 提交于 2019-12-18 04:55:17
问题 Is it possible to play wav files with AudioTrack from the resources folder raw? It tried many ways to reference the raw files in my Android project, but I got a lot of exceptions. This is what I have now, but when I press the button, no sound plays. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button buttonPlayAudioTrack = (Button) findViewById(R.id.buttonPlayAudioTrack); buttonPlayAudioTrack.setOnClickListener(this); int minBufferSize = AudioTrack

How to addTrack in MediaStream in WebRTC

断了今生、忘了曾经 提交于 2019-12-17 06:53:47
问题 I'm using webrtc to communicate between to peers. I wan't to add new track to old generated stream, as I wan't to give functionality to users to switch their microphones during audio communications. The code I'm using is, Let "pc" be the peerConnection object through which audio communication takes place & "newStream" be the new generated MediaStream got from getUserMedia function with new selected microphone device. var localStreams = pc.getLocalStreams()[0]; localStreams.removeTrack

Audiotrack doesn't stop with audioTrack.stop() since last Android version

自闭症网瘾萝莉.ら 提交于 2019-12-13 17:27:44
问题 I'm using an Audiotrack for looping some music. I was using the method audioTrack.stop() to stop, but since the last update it doesn't work. From the last version only this way works: audioTrack.pause(); audioTrack.flush(); But this method doesn't stop the audio in the previous Android versions. Anyone knows what method works in all the Android versions ? 来源: https://stackoverflow.com/questions/24479158/audiotrack-doesnt-stop-with-audiotrack-stop-since-last-android-version

How to change the duration of the audiotrack by an infinite loop?

我是研究僧i 提交于 2019-12-13 06:11:56
问题 How to change the duration of the audiotrack by an infinite loop? I understand that I must apply the following line before audioTrack.play() : audioTrack.setLoopPoints (0, generatedSnd.length, -1); For example, I want the duration will be half a second, therefore, the "duration" variable of type "int" isn't valid. To do so I want the sound to play repeatedly and control the time to stop with a Timer. The code is: private int duration = 1; // seconds private int sampleRate = 44100; private