audiotrack

Multiple AudioTrack Instances (and Threads) in a Single Service?

送分小仙女□ 提交于 2019-12-06 16:50:28
I have a streaming music application that can play two streams simultaneously by using two separate services utilizing one AudioTrack each, on their own threads. Now I'd like to able to play more than two streams, and I guess having more services is not the way to go. Is it possible to have a single service having dynamically instantiated AudioTracks? How can I implement separate threads for each of the AudioTrack instances? How will I access the dynamically instantiated AudioTracks? 来源: https://stackoverflow.com/questions/27493521/multiple-audiotrack-instances-and-threads-in-a-single-service

Android AudioTrack slow playback

三世轮回 提交于 2019-12-06 16:14:05
I'm trying to stream music in using AudioTrack. The track plays, but the audio plays at half the rate. It's like the song has become slow motion. try{ AudioTrack track= new AudioTrack( AudioManager.STREAM_MUSIC, 44100, android.media.AudioFormat.CHANNEL_CONFIGURATION_MONO, android.media.AudioFormat.ENCODING_PCM_16BIT, android.media.AudioTrack.getMinBufferSize( 44100, android.media.AudioFormat.CHANNEL_CONFIGURATION_STEREO, android.media.AudioFormat.ENCODING_PCM_16BIT ), AudioTrack.MODE_STREAM ); System.out.println("Min buffer: " + android.media.AudioTrack.getMinBufferSize( 44100, android.media

Android Tempo/playback speed change

六月ゝ 毕业季﹏ 提交于 2019-12-06 04:40:47
问题 I am creating an Android app which requires the real time change of playback rate/speed. I have searched all over the internet and have seen many solutions including Tutorials for OpenSL ES for Android How to change audio tempo and pitch individuality using ffmpeg? As i am relatively new to development and android some of these are simply out of my leauge. Many of these examples talk about Soundpool but this api does not work with large files. After looking through API's and classes i found

Unable to retrieve AudioTrack pointer for write()

ぐ巨炮叔叔 提交于 2019-12-06 03:37:53
问题 I am trying to implement AudioTrack to retrieve audio in my android device for incoming call from IAX but facing exception after some while . private void writeBuff(short[] buf) { try { if (this.track == null) { Log.w("IAX2Audio", "write() without an AudioTrack"); return; } int written = 0; while (written < buf.length) { if (this.track != null) { int res; res = this.track.write(buf, written, buf.length - written); switch (res) { case AudioTrack.ERROR_INVALID_OPERATION: Log.e("IAX2Audio",

How to stream data from MediaCodec to AudioTrack with Xamarin for Android

时光总嘲笑我的痴心妄想 提交于 2019-12-05 12:23:39
I'm trying to decode a mp3 file and stream it to AudioTrack. It all works fine but causes a lot of GC on the Java side. I've made sure to not allocate memory in my play/stream loop and blame ByteBuffer.Get(byte[], int, int) binding of allocating a temp Java array. Anyone can confirm and/or show a better way of feeding data from MediaCodec to AudioTrack? (I know API 21 introduced AudioTrack.write(ByteBuffer, ...)) Thanks Here is what I do: byte[] audioBuffer = new byte[...]; ... ByteBuffer codecOutputBuffer = codecOutputBuffers[outputIndex]; // The next line seems to be the source of a lot of

Android:Creating Wave file using Raw PCM, the wave file does not play

浪尽此生 提交于 2019-12-05 10:00:04
问题 I have created the header for the wave file, but the wave file which is created does not play. I have used this https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ as a reference to create the wave header. public void WriteWaveFileHeader() throws IOException { File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/aaa.wav"); f.createNewFile(); FileOutputStream fos = new FileOutputStream(f); long longSampleRate=44100; int channels= AudioFormat.CHANNEL_IN_MONO;

Cannot stop AudioTrack on Android 5

落花浮王杯 提交于 2019-12-04 20:19:17
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("audio device plugged"); boolean mic = intent.getIntExtra("microphone", 0) == 1; if(mic) { log.debug(

Android Tempo/playback speed change

对着背影说爱祢 提交于 2019-12-04 10:30:16
I am creating an Android app which requires the real time change of playback rate/speed. I have searched all over the internet and have seen many solutions including Tutorials for OpenSL ES for Android How to change audio tempo and pitch individuality using ffmpeg? As i am relatively new to development and android some of these are simply out of my leauge. Many of these examples talk about Soundpool but this api does not work with large files. After looking through API's and classes i found the method setPlaybackRate(int sampleRateInHz) under the AudioTrack class. http://developer.android.com

Unable to retrieve AudioTrack pointer for write()

久未见 提交于 2019-12-04 07:32:04
I am trying to implement AudioTrack to retrieve audio in my android device for incoming call from IAX but facing exception after some while . private void writeBuff(short[] buf) { try { if (this.track == null) { Log.w("IAX2Audio", "write() without an AudioTrack"); return; } int written = 0; while (written < buf.length) { if (this.track != null) { int res; res = this.track.write(buf, written, buf.length - written); switch (res) { case AudioTrack.ERROR_INVALID_OPERATION: Log.e("IAX2Audio", "Invalid write()"); return; case AudioTrack.ERROR_BAD_VALUE: Log.e("IAX2Audio", "Bad arguments to write()")

AudioTrack: should I use an Asynctask, a Thread or a Handler?

£可爱£侵袭症+ 提交于 2019-12-04 07:05:55
问题 In Android: I am trying to play a wav file of size 230mb and 20 min whose properties are as below: ffmpeg -i 1.wav Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s The following is the code in android: float volchange=0.5f; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Code to set the volume change variable for the audiotrack Button volup = (Button) findViewById