audiotrack

Playing sound over speakers while playing music through headphones

帅比萌擦擦* 提交于 2019-12-28 06:24:48
问题 I have an AudioTrack streaming via headphones. I have to send a SoundPool to built-in speakers only, without interrupting the AudioTrack playing over the headphones. Any hacks gangsters? 回答1: Many Android devices use a single output thread in the AudioFlinger / audio HAL for all local playback (earpiece, speaker, wired headset/headphones), making different routing of two tracks simultaneously impossible (which is why on many devices the media streams are forcibly muted if a notification is

Android MediaCodec API - Music Plays on Emulator, Not on the Device

那年仲夏 提交于 2019-12-25 08:12:03
问题 The code given below works fine on the emulator, but not the device. I found the following lines that looked suspicious to me: V/MediaExtractor(5030): Autodetected media content as 'audio/mpeg' with confidence 0.20 V/ChromiumHTTPDataSource(5030): mContentSize is undefined or network might be disconnected V/ChromiumHTTPDataSource(5030): mContentSize is undefined or network might be disconnected D/com.example.mediacodectest(5030): MIME TYPE: audio/mpeg I am looking for hints/suggestions. Thanks

audio codec dequeueInputBuffer returns -1 on device

隐身守侯 提交于 2019-12-25 05:27:40
问题 I'm trying to play some audio taken from an MPEG2 transport (.ts) file. I'm getting the audio stream via MediaExtractor, using readSampleData to copy samples to MediaCodec input buffers, then writing the MediaCodec output buffer to an AudioTrack. MediaExtractor indicates the audio MIME type as "audio/mp4a-latm". All this works wonderfully on a Nexus 7 2013 tablet. But it does not work at all on an inexpensive Neutab x7 tablet. The problem is that after a few samples, dequeueInputBuffer

Regulate Android AudioTrack playback speed

南楼画角 提交于 2019-12-25 01:34:16
问题 I'm currently trying to playback audio using AudioTrack. Audio is received over the network and application continuously read data and add to an internal buffer. A separate thread is consuming data and using AudioTrack to playback. Problems: Audio playback fluctuate (feels like audio drop at a regular interval) continuously making it unclear. Playback speed is too high or too low making them unrealistic. In order to avoid the network latency and other factors I made the application to wait

Using AudioTrack in AudioTrack.MODE_STATIC?

南笙酒味 提交于 2019-12-24 14:56:22
问题 I've found lots of tutorials and posts showing how to use AudioTrack to play wav files in AudioTrack.MODE_STREAM and I've successfully implemented this example. However I'm having issues with performance when playing multiple audio tracks at once and thinking that I should first create the tracks using AudioTrack.MODE_STATIC then just call play each time. I can't find any resources on how to implement this. How can I do this? Thanks 回答1: The two main sticking points for me were realizing that

Playing repeated AudioTrack in android activity

守給你的承諾、 提交于 2019-12-24 11:37:53
问题 I want to play a tone pulse repeated at a specified rate, e.g. 3 times a second. It works about 20 times and then crashes as below. void playSound() { final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length, AudioTrack.MODE_STATIC); audioTrack.write(generatedSnd, 0, generatedSnd.length); audioTrack.play(); } In an asynctask I run a continuous loop that checks the time and

Use AudioTrack with JLayer decoder

六月ゝ 毕业季﹏ 提交于 2019-12-24 00:55:46
问题 I'm working on the Android application which is using JLayer library to decode MP3 file (I need access to audio samples) and AudioTrack object to play it. I have something like this: int timeMarker = 0; int timeStep = 5000; while (!isCancelled()) { outSignalBuffer = decode(fileToPlay.getPath(), timeMarker, timeStep, bufferSize); audioTrack.write(outSignalBuffer, 0, outSignalBuffer.length); //publishProgress(outSignalBuffer); timeMarker += timeStep; } This code is placed in my custom player

uninitialized AudioTrack exception when I try to generate tone on 22nd time

前提是你 提交于 2019-12-24 00:25:01
问题 I have a requirement that I need to display a dial pad like screen and I have to generate 1khz tone (not DTMF tone) whenever user presses on a dial pad buttons. I have used the code from the below link to generate 1 khz tone: Playing an arbitrary tone with Android When I started dialing buttons on my dialpad screen till 21 presses it is successfully generating tone but after 22nd attempt I am getting Application Not Responding (ANR) error and I need to close the app. Below is my code: final

How can I manually change the gain level of an Android AudioTrack stream using a scalar?

点点圈 提交于 2019-12-23 17:59:50
问题 I'm using the Android AudioTrack object to stream a 16bit mono PCM file. My code reads a double from a DataInputStream, converts it to 8 bytes, and then saves that 8 bytes to a buffer to be written to the AudioTrack. This works fine. But now, I'm trying to adjust the gain by multiplying the double by a scalar (like 0.5). When I do this, it makes my audio terribly distorted. I have tried using floats instead of doubles, and I get the same result. Is there a better way to go about changing the

Android audio too fast on some devices with MediaCodec and AudioTrack

ぃ、小莉子 提交于 2019-12-23 12:43:18
问题 I am decoding audio using MediaExtractor , MediaCodec , and AudioTrack . I am configuring the AudioTrack using the MediaFormat returned by MediaCodec.getOutputFormat() after receiving MediaCodec.INFO_OUTPUT_FORMAT_CHANGED from the MediaCodec . On some devices, this results in speeded up audio, while the MediaFormat returned by the MediaExtractor works correctly. (On other devices, the reverse is true.) Here are some details: The audio files in question are largely 22050 Hz mono MP3s. The