audiotrack

Android录制和播放AudioRecord和AudioTrack

大兔子大兔子 提交于 2021-02-13 11:04:24
package com.esa.audio; import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioRecord; import android.media.AudioTrack; import android.media.MediaRecorder; public class Audio { public static final int AUDIO_SOURCE = MediaRecorder.AudioSource.MIC; public static final int STREAM_TYPE = AudioManager.STREAM_MUSIC; public static final int SAMPLE_RATE_IN_HZ = 8000;// 44100 public static final int CHANNEL_CONFIG = AudioFormat.CHANNEL_CONFIGURATION_MONO;// AudioTrack和AudioRecord都能用 public static final int RECORD_CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO;

Xamarin Android C# play audio stream (online radio)

怎甘沉沦 提交于 2021-02-10 13:36:11
问题 I have a URL of online-radio and I'd like to play it. So, I've done it this way: reading stream and writing it to byte array and playing it with audioTrack class. Here's the code: private static async Task Play() { using (WebClient wcDownload = new WebClient()) { // Create a request to the file we are downloading WebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://media.vmariel.ru:8000/puls"); // Set default authentication for retrieving the file webRequest.Credentials =

How to tell when AudioTrack object has finished playing?

杀马特。学长 韩版系。学妹 提交于 2020-01-20 05:40:24
问题 I'm trying to play a PCM file in Android using the AudioTrack class. I can get the file to play just fine, but I cannot reliably tell when playback has finished. AudioTrack.getPlayState says playback has stopped when it hasn't finished playing. I'm having the same problem with AudioTrack.setNotificationMarkerPosition , and I'm pretty sure my marker is set to the end of the file (although I'm not completely sure I'm doing it right). Likewise, playback continues when getPlaybackHeadPosition is

Immediate Audio Input & Output Android

╄→尐↘猪︶ㄣ 提交于 2020-01-12 12:53:45
问题 In my Android App, I would like to take in some audio from the mic of the smartphone and play it immediately, live, like a microphone, with no lag. I am currently thinking of using AudioRecord and AudioTrack classes (from what I have read), but I'm not quite sure how to proceed. I checked out some other questions on Stack Overflow but they don't exactly answer what I would like to do. And most are from 2012. So how can I use these classes to input and output audio simultaneously? ALSO: I had

Play Audio (mp3, ogg) from sd card with AudioTrack

霸气de小男生 提交于 2020-01-12 08:27:35
问题 I want to play audio file from SD card with AudioTrack. I've tried with this code: int minBufferSize = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT); int bufferSize = 512; AudioTrack at = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, minBufferSize, AudioTrack.MODE_STREAM); int i = 0; byte[] s = new byte[bufferSize]; FileInputStream fin = new FileInputStream

AudioTrack in MODE_STREAM has no sound

百般思念 提交于 2020-01-04 15:50:41
问题 I've been stuck on this problem for days. I'm at the stage now where I'm just trying to get a working example to build from, but I can't even reach that point. My question is based on this example. I've included the source (and solution) into my own code, and can see the buffer is being written to, but no sound comes from the device. I'm struggling to identify how to debug this further. package com.example.audio; import com.example.R; import java.io.IOException; import java.io.InputStream;

AudioTrack setStereoVolume deprecated

£可爱£侵袭症+ 提交于 2020-01-04 06:14:26
问题 I did not manage to find solution what to use instead of deprecated AudioTrack's method setStereoVolume. There is info about this in reference, but I am not sure how to use setVolume for muting left/right channel. This method was deprecated in API level 21. Applications should use setVolume(float) instead, as it more gracefully scales down to mono, and up to multi-channel content beyond stereo. I need to play only one channel at a time, but I cannot find appropriate solution. I've already

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

匆匆过客 提交于 2020-01-03 02:51:07
问题 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? 来源:

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

可紊 提交于 2020-01-02 05:38:07
问题 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

AudioTrack: play() called on uninitialized AudioTrack

我的未来我决定 提交于 2019-12-29 07:34:06
问题 I'm experimenting with AudioTrack class. Basically, my app has to generate a sound when the user touches a specific object on screen. I've used this example as a guide. My app seems to work as it should but usually after touching the screen for about a minute it crashes: 07-02 20:40:53.459: E/AndroidRuntime(11973): FATAL EXCEPTION: Thread-10 07-02 20:40:53.459: E/AndroidRuntime(11973): java.lang.IllegalStateException: play() called on uninitialized AudioTrack. 07-02 20:40:53.459: E