java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.otaliastudios.transcoder.source.DataSource.isInitialized()' on a null object reference
String srcPath = "/storage/emulated/0/Download/sample.mp3";
String desPath = "/storage/emulated/0/Download/hmm.aac";
Log.e(TAG, "onActivityResult: "+srcPath);
DefaultAudioStrategy strategy = DefaultAudioStrategy.builder()
.channels(DefaultAudioStrategy.CHANNELS_AS_INPUT)
.channels(1)
.channels(2)
.sampleRate(DefaultAudioStrategy.SAMPLE_RATE_AS_INPUT)
.sampleRate(44100)
.sampleRate(30000)
.bitRate(DefaultAudioStrategy.BITRATE_UNKNOWN)
.build();
Transcoder.into(desPath)
.addDataSource(srcPath)
.setAudioTrackStrategy(strategy)
.setListener(new TranscoderListener() {
@Override
public void onTranscodeProgress(double progress) {
Log.e(TAG, "onTranscodeProgress: ");
}
@Override
public void onTranscodeCompleted(int successCode) {
Log.e(TAG, "onTranscodeCompleted: ");
}
@Override
public void onTranscodeCanceled() {
Log.e(TAG, "onTranscodeCanceled: ");
}
@Override
public void onTranscodeFailed(@NonNull Throwable exception) {
Log.e(TAG, "onTranscodeFailed: "+exception);
}
}).transcode();
Whenever i a running this code i am getting this error
**
2022-07-31 17:39:10.337 10749-10822/com.example.transcoder I/TranscodeEngine: transcode(): called...
2022-07-31 17:39:10.338 10749-10822/com.example.transcoder I/DataSources: initializing videoSources...
2022-07-31 17:39:10.338 10749-10822/com.example.transcoder E/TranscodeEngine: Unexpected error while transcoding.
java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.otaliastudios.transcoder.source.DataSource.isInitialized()' on a null object reference
at com.otaliastudios.transcoder.source.DataSourceWrapper.isInitialized(DataSourceWrapper.java:99)
at com.otaliastudios.transcoder.internal.DataSources.init(DataSources.kt:25)
at com.otaliastudios.transcoder.internal.DataSources.
I am also getting this error when using .addDataSource(srcPath).
Although, this is working .addDataSource(context, uri).
I am also getting this error when using .addDataSource(srcPath).
Although, this is working .addDataSource(context, uri).
Actually i have tried that also i am still getting the same error
I am also getting this error when using .addDataSource(srcPath).
Although, this is working .addDataSource(context, uri).
Now working fine
How did you fix it?
How did you fix it?
Just pass Uri like this--------> (Uri uri = Uri.fromFile(new File(input.getAbsolutePath()));)