the media extractor works perfectly for many other versions.
But when doing on android 26 it throws
java.io.IOException: Failed to instantiate extractor.
This is how it is being set. The videoFileDescriptor is perfectly valid.
The error is in the last line .setDataSource and in apis 26.
private fun getVideoData(videoFileDescriptor: ParcelFileDescriptor?): Pair<MediaExtractor?, MediaFormat?> {
val videoExtractor = MediaExtractor()
videoExtractor.setDataSource(videoFileDescriptor.fileDescriptor)
Related
I am writing an Android app which handle images on device.
I open the file descriptor of images using ContentResolver's openFileDescriptor(). But it throws an exception which I can't find from Android API doc for some images. It works fine for most images. About the problematic images, I can see the images without problem in the default gallery app.
Is there someone who knows why it happens?
Fatal Exception: java.lang.IllegalStateException: java.io.IOException: Failed to redact
/storage/emulated/0/DCIM/60s-70s/a2acf4b43dd94f609d605dacc6f0a2e0.jpg
at android.os.Parcel.createExceptionOrNull(Parcel.java:2393)
at android.os.Parcel.createException(Parcel.java:2369)
at android.os.Parcel.readException(Parcel.java:2352)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:781)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1986)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1801)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1634)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1581)
--- snip ---
My code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val pfd = mContentResolver.openFileDescriptor(
Uri.parse(strContentUri),
"r"
)
// strContentUri is like "content://media/external/images/media/21052"
I'm trying to use non-deprecated methods for storing an image. However, the suggested context.getExternalFilesDir crashes in the emulator on the first line in the following.
val albumFolder = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!
i { "Writing file to ${albumFolder.absolutePath} "}
albumFolder.mkdirs()
check(albumFolder.exists() && albumFolder.canWrite()) { "Missing or non-writable folder: ${albumFolder.absolutePath}"}
It throws 2 errors, then dies on a NPE for the first line.
E/vold: Failed to find mounted volume for /storage/emulated/0/Android/data/MYAPP/files/Pictures/
W/ContextImpl: Failed to ensure /storage/emulated/0/Android/data/MYAPP/files/Pictures: android.os.ServiceSpecificException: (code -22)
I have a Qt code with a QSound object that is supposed to read two wav files on a thread.
My code works on iOS simulator, but not on Android.
My thread code that reads wav files :
ClickThread::ClickThread(): highClickFile("://high_click.wav"), lowClickFile("://low_click.wav"), isRunning(false)
{
this->highClick = new QSound(highClickFile);
this->lowClick = new QSound(lowClickFile);
this->setPeriod(120);
}
void ClickThread::process(){
while(this->isRunning == true)
{ if(!this->isRunning) break;
highClick->play();
QThread::msleep(period);
highClick->stop();
if(!this->isRunning) break;
lowClick->play();
QThread::msleep(period);
lowClick->stop();
if(!this->isRunning) break;
lowClick->play();
QThread::msleep(period);
lowClick->stop();
if(!this->isRunning) break;
lowClick->play();
QThread::msleep(period);
lowClick->stop();
}
}
There is the error message I got :
W linker : Warning: "/data/data/org.qtproject.example.MyProject/qt-reserved-files/plugins/audio/libqtaudio_opensles.so" has unsupported flags DT_FLAGS_1=0x80 (ignoring unsupported flags)
D : PlayerBase::PlayerBase()
D : TrackPlayerBase::TrackPlayerBase()
I libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x4, using default mask 0x1 based on channel count of 1)
I AudioTrack: createTrack_l(0): AUDIO_OUTPUT_FLAG_FAST successful; frameCount 0 -> 1322
E android.media.AudioTrack: getMinBufferSize(): Invalid audio format.
W libc : malloc(4294967292) failed: returning null pointer
F libc : /Volumes/Android/buildbot/src/android/ndk-release-r20/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73: abort_message: assertion "terminating with uncaught exception of type std::bad_alloc: std::bad_alloc" failed
F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 7670 (QtThread), pid 6740 (.MyProject)
Thanks for your answers
P
EDIT :
The problem was that my wav file was encoded in 24 bits. Android doesn't seem to use this kind of encoding for PCM files, referring to this website :
https://developer.android.com/reference/android/media/AudioFormat
we only can have 8, 16 or 32 bits.
So, I used FFmpeg to encode my wav files in 16 bits and now my code works !
Check that link for an exemple of encoding with FFmpeg :
ffmpeg FLAC 24 bit 96khz to 16 bit 48khz
Pierre.
I have a test suite that open JSON files. The tests do not pass on emulator <= API 23 and work fine on newer API Level.
There are two different kinds of exceptions:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 1025 $.ajsonelement
and
com.google.gson.JsonSyntaxException: java.io.EOFException: End of input at line 1 column 1025 path $.ajsonelement.
The weird thing is that those files work fine when I run the app and open them manually in the simulator.
I'm using gson but the problem also appears with Moshi.
Found the issue. The json files were in moduleName/src/test/resources/configs/. I moved them to moduleName/src/test/assets/configs/
The code to load them was:
val assetConfig = InstrumentationRegistry
.getInstrumentation()
.context
.assets
.open(configFileName)
val scanner = Scanner(assetConfig)
return scanner.useDelimiter("\\Z").next() Charsets.UTF_8))
I replaced it with a Guava helper:
val assetConfig = InstrumentationRegistry
.getInstrumentation()
.context
.assets
.open(configFileName)
return CharStreams.toString(InputStreamReader(assetConfig, Charsets.UTF_8))
Everything loads fine for all emulator between API 18 and 26.
I am trying to pipeline some audio over a udp socket on android using eclipse
I keep getting the following error
"The method fromDatagramSocket(DatagramSocket) is undefined for the type ParcelFileDescriptor"
The android docs show that such a method is already available and I believe this is the proper way to create a UDP pipeline
Reference:
http://developer.android.com/reference/android/os/ParcelFileDescriptor.html#fromDatagramSocket(java.net.DatagramSocket)
Code :
DatagramSocket socket = new DatagramSocket(port, InetAddress.getByName(hostnameUDP));
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromDatagramSocket(socket);
The problem was with the included Android Library which was Android 2.2
Changed it to Android 4.3 and it worked
Apparently the older version of the Android library did not have UDP defined