1

我已经为平台 8、10 和 13 构建了 gstreamer_ndk_bundle,没有任何错误和问题。现在我正试图让 gstreamer-java 在 android 上工作,我想我让它工作了。JNA 运行良好(在我的 lib 上进行了测试),我已将所有缺少Structure.setFieldOrder()的调用添加到 gstreamer-java 代码中,删除了 Android 上不存在的所有类和包,它可以在模拟器上编译和运行。另外,我在该平台模拟器上使用了为特定平台编译的 gstreamer 库。

我使用此代码播放 Mp3 文件:

File file = new File(getExternalFilesDir(null),"demo_tunes.mp3" );

try 
{
    InputStream is = getResources().openRawResource(R.raw.test);
    OutputStream os = new FileOutputStream(file);
    byte[] data = new byte[is.available()];
    is.read(data);
    os.write(data);
    is.close();
    os.close();
} 
catch (IOException e) 
{
    Log.w("ExternalStorage", "Error writing " + file, e);
}

Gst.init("AudioPlayer", new String[]{"--gst-plugin-path=/data/data/org.gstreamer.marko/lib"});

Pipeline pipe  = new Pipeline("PipeLine"); 
Element src = ElementFactory.make("filesrc","Input File"); 
src.set("location", file.getAbsolutePath()); 
Element decode = ElementFactory.make("decodebin2", "Decode");
Element sink = ElementFactory.make("audioflingersink", "Sink");
pipe.addMany(src, decode, sink); 
Element.linkMany(src, decode, sink);

pipe.play();

所有需要的库及其依赖项都是这样加载的:

static
{

    System.loadLibrary("glib-2.0");
    System.loadLibrary("gmodule-2.0");
    System.loadLibrary("gthread-2.0");
    System.loadLibrary("gobject-2.0");
    System.loadLibrary("gstreamer-0.10");

    //Libraries for base plugins
    System.loadLibrary("gstbase-0.10");
    System.loadLibrary("gstpbutils-0.10");          
    System.loadLibrary("gstinterfaces-0.10");
    System.loadLibrary("gstvideo-0.10");
    System.loadLibrary("gstplaybin");

    //Base plugins
    System.loadLibrary("gstcoreelements");
    System.loadLibrary("gstautodetect");

    System.loadLibrary("gsttag-0.10");
    System.loadLibrary("gstaudio-0.10");
    System.loadLibrary("gstriff-0.10");
    System.loadLibrary("ogg");
    System.loadLibrary("gstogg");
    System.loadLibrary("gstaudioflinger");
    System.loadLibrary("mad");
    System.loadLibrary("gstmad");

    System.loadLibrary("gstdecodebin2");
    System.loadLibrary("gstautodetect"); 
}

应用程序运行,但我没有听到任何声音!此外,我还尝试将设备的音量调到最大,但也没有声音:

        AudioManager audman = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        audman.setStreamVolume(AudioManager.STREAM_MUSIC, audman.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
        audman.setStreamVolume(AudioManager.STREAM_SYSTEM, audman.getStreamMaxVolume(AudioManager.STREAM_SYSTEM), 0);
        audman.setStreamVolume(AudioManager.STREAM_DTMF, audman.getStreamMaxVolume(AudioManager.STREAM_DTMF), 0);

在 Log cat 输出中,我可以看到创建了 audioflinger sink 但没有声音:

06-29 20:07:09.407: GstAudioFlingerSink(462): gst_audioflinger_sink_getcaps,0x0
06-29 20:07:09.434: GstAudioFlingerSink(462): creating ringbuffer
06-29 20:07:09.434: GstAudioFlingerSink(462): created ringbuffer @0x1fc810
06-29 20:07:09.447: GstAudioFlingerSink(462): >gst_android_audioringbuffer_open_device
06-29 20:07:09.447: GstAudioFlingerSink(462): gst_audioflinger_sink_open
06-29 20:07:09.447: audioflinger_wrapper(462): Create AudioTrack successfully 0x1f6e70
06-29 20:07:09.447: GstAudioFlingerSink(462): create a new flinger, 0x1f6e70

我错过了什么?我也尝试了这个PlayBinPlayBinMediaPlayer并尝试了OGG文件,也运行了,但没有声音......

4

0 回答 0