媒体提取秀"未能实例提取" [英] media extractor show "failed to instantiate extractor"

查看:179
本文介绍了媒体提取秀"未能实例提取"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在媒体工作的提取在Android上OGG文件格式的音频流。
我已经写了一些code与谷歌文档的帮助。但它不在所有工作。
可我已经写了错误的code或语法,因为我的学生。
它告诉我没有实例提取

I am trying to work on media extractor for audio streaming of OGG file format on android. I have written some code with help of google documents. but it doesn't work at all. May be i have Written a wrong code or syntax As i am student. it show me failed to instantiate extractor

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

MediaExtractor extractor = new MediaExtractor();
extractor.setDataSource("http://examplelink.com/ogg");// I cant put real link so sorry for that
int numTracks = extractor.getTrackCount();
for (int i = 0; i < numTracks; ++i) {
    MediaFormat format = extractor.getTrackFormat(i);
    String mime = format.getString(MediaFormat.KEY_MIME);
    extractor.selectTrack(i);

    ByteBuffer inputBuffer = ByteBuffer.allocate(1024);
    while (extractor.readSampleData(inputBuffer,0) >= 0) {
            int trackIndex = (int) extractor.getSampleTime();
            long presentationTimeUs = extractor.getSampleTime();
    }

    MediaCodec codec = MediaCodec.createDecoderByType(mime);
    codec.configure(format, null /* surface */, null /* crypto */, 0 /* flags */);
    codec.start();
    ByteBuffer[] inputBuffers = codec.getInputBuffers();
    ByteBuffer[] outputBuffers = codec.getOutputBuffers();
    format = codec.getOutputFormat();
    Long timeoutUs=(long) 1;
    for (;;) {
        int inputBufferIndex = codec.dequeueInputBuffer(timeoutUs);
        if (inputBufferIndex >= 0) {
            // fill inputBuffers[inputBufferIndex] with valid data
            codec.queueInputBuffer(inputBufferIndex, 0, 128, 0,0);
        }
        MediaCodec.BufferInfo info = new BufferInfo();
        int outputBufferIndex = codec.dequeueOutputBuffer(info, timeoutUs);
        if (outputBufferIndex >= 0) {
            // outputBuffer is ready to be processed or rendered.
            codec.releaseOutputBuffer(outputBufferIndex, false);
        } else if (outputBufferIndex == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
            outputBuffers = codec.getOutputBuffers();
        } else if (outputBufferIndex == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
            // Subsequent data will conform to new format.
            format = codec.getOutputFormat();
            AudioTrack mAudioTrack = null;
            mAudioTrack.setPlaybackRate(format.getInteger(MediaFormat.KEY_SAMPLE_RATE));
        }
        codec.stop();
        codec.release();
        codec = null;
    }
}

}

推荐答案

我假设你的问题是为什么没有在所有的工作?
通常,这是太大了一个问题,但在这种情况下,它看起来像你对我有没有在所有明白怎么MediaExtractor&放大器;媒体codeC的工作。

I ASSUME your question is "why doesn't it work at all?" Usually, this is much too big a question, but in this case it looks to me like you have not understood at all how the MediaExtractor & MediaCodec work.

不都是你的错,但。该文档是神秘的,把它亲切。
不过,我已经成功地播放音频文件这种方式。

Not all your fault though. The documentation is cryptic, to put it kindly. However I have succeeded in playing audio files this way.

我的方案假设媒体codeC实现缓存的异步队列。似乎有在此队列中大约4缓冲区。

My scheme assumes that MediaCodec implements an asynchronous queue of buffers. There seem to be about 4 buffers in this queue.

于是我就用2个线程:一个线程把数据从MediaExtractor到队列中,而另一个线程从队列中取出德codeD音频输出,并将其写入到一个AudioTrack

So I use 2 threads: One thread puts data from the MediaExtractor into the queue, and another thread takes decoded audio out from the queue and writes it to an AudioTrack.

然后我需要非常小心,以避免在寻道,例如死锁。我结束了一个很多code比你。我不知道如何避免!

I Then need to be very careful to avoid deadlock during a seek, for example. And I end up with a lot more code than yours. I don't know how to avoid that !

我想尝试视频。任何有用的参考文献是接入点preciated!

I am thinking of trying video. Any helpful references would be appreciated !

不要

这篇关于媒体提取秀&QUOT;未能实例提取&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆