3

我在 Galaxy Tab 上播放流媒体* 音频时遇到了一些问题(适用于 HTC Desire HD 和 Nexus One)。当我创建 MediaPlayer 对象时,它会产生如下错误:

02-09 02:21:39.088: VERBOSE/MediaPlayer-JNI(9325): native_setup
02-09 02:21:39.088: VERBOSE/MediaPlayer(9325): constructor
02-09 02:21:39.088: VERBOSE/MediaPlayer(9325): setListener
02-09 02:21:39.092: INFO/MediaPlayer(9325): uri is:http://147.83.39.86:3200/osgi/files/TTS/1297185775715.ogg
02-09 02:21:39.092: INFO/MediaPlayer(9325): path is null
02-09 02:21:39.092: DEBUG/MediaPlayer(9325): Couldn't open file on client side, trying server side
02-09 02:21:39.092: VERBOSE/MediaPlayer-JNI(9325): setDataSource: path http://147.83.39.86:3200/osgi/files/TTS/1297185775715.ogg
02-09 02:21:39.092: VERBOSE/MediaPlayer(9325): setDataSource(http://147.83.39.86:3200/osgi/files/TTS/1297185775715.ogg)
02-09 02:21:39.092: ERROR/MediaPlayerService(2392): Failed to create player object
02-09 02:21:39.092: ERROR/MediaPlayer(9325): Unable to to create media player
02-09 02:21:39.104: DEBUG/MediaPlayer(9325): create failed:
02-09 02:21:39.104: DEBUG/MediaPlayer(9325): java.io.IOException: setDataSource failed.: status=0x80000000
02-09 02:21:39.104: DEBUG/MediaPlayer(9325):     at android.media.MediaPlayer.setDataSource(Native Method)
02-09 02:21:39.104: DEBUG/MediaPlayer(9325):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:745)
02-09 02:21:39.104: DEBUG/MediaPlayer(9325):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:675)
02-09 02:21:39.104: DEBUG/MediaPlayer(9325):     at android.media.MediaPlayer.create(MediaPlayer.java:611)
02-09 02:21:39.104: DEBUG/MediaPlayer(9325):     at android.media.MediaPlayer.create(MediaPlayer.java:592)
02-09 02:21:39.104: DEBUG/MediaPlayer(9325):     at com.vodafone.inredis.movil.interfazweb.InredisWebViewClient.shouldOverrideUrlLoading(InredisWebViewClient.java:37)

这就是我创建 MediaPlayer 对象的方式,没什么奇怪的:

Uri tempPath = Uri.parse(url);
player = MediaPlayer.create(interfazWeb, tempPath);
if (player != null){
  player.start();
} else {
  Log.e(TAG, "No se puede abrir el audio:" + url);
}
return true;

并且提供更多信息,我可以说我测试了通过的url,我可以用原生浏览器下载并正常播放。显然我可以用我的桌面浏览器播放它。

有没有人在提到的设备上遇到过这个问题?

提前致谢。

######## 编辑 ##############

我还没有解决这个问题,但我一直在研究,现在我在一个单独的线程中下载文件,将它保存到一个临时文件并使用MediaPlayer. 它会产生另一种错误,我怀疑文件夹和权限,但我还不确定。

因此,现在我有了可以使用 Galaxy 的本机播放器播放的临时文件,但不能使用我在代码中创建的文件,以及另一条日志跟踪,这没有给我任何提示。

02-10 01:36:36.945: VERBOSE/MediaPlayer-JNI(8371): native_setup
02-10 01:36:36.945: VERBOSE/MediaPlayer(8371): constructor
02-10 01:36:36.945: VERBOSE/MediaPlayer(8371): setListener
02-10 01:36:36.948: VERBOSE/MediaPlayer-JNI(8371): setDataSource: path /sdcard/audioTmp360988.ogg
02-10 01:36:36.948: VERBOSE/MediaPlayer(8371): setDataSource(/sdcard/audioTmp360988.ogg)
02-10 01:36:36.952: VERBOSE/MediaPlayer(8371): prepare
02-10 01:36:36.952: ERROR/MediaPlayerService(2394): Client::notify In
02-10 01:36:36.952: ERROR/MediaPlayer(8371): message received msg=1, ext1=0, ext2=0
02-10 01:36:36.952: VERBOSE/MediaPlayer(8371): prepared
02-10 01:36:36.952: VERBOSE/MediaPlayer(8371): signal application thread
02-10 01:36:36.952: ERROR/MediaPlayer(8371): callback application
02-10 01:36:36.952: ERROR/MediaPlayer(8371): back from callback
02-10 01:36:36.952: VERBOSE/MediaPlayer(8371): prepare complete - status=0
02-10 01:36:41.437: VERBOSE/MediaPlayer-JNI(8371): native_finalize
02-10 01:36:41.437: VERBOSE/MediaPlayer-JNI(8371): release
02-10 01:36:41.437: VERBOSE/MediaPlayer(8371): setListener
02-10 01:36:41.437: VERBOSE/MediaPlayer(8371): disconnect
02-10 01:36:41.437: VERBOSE/MediaPlayer(8371): destructor
02-10 01:36:41.437: VERBOSE/MediaPlayer(8371): disconnect

来吧,我不能是唯一的一个!

4

2 回答 2

3

带有 MediaPlayer 的 WAV 和 OGG 音频流在 Samsung Galaxy TAB(带有 FroYo)上不起作用。我一直在测试,我使用了 API Demo (8),特别是这段代码/Demos/src/com/example/android/apis/media/MediaPlayerDemo_Audio.java

    private void playAudio(Integer media) {
        try {
            switch (media) {
                case LOCAL_AUDIO:
                    /**
                     * TODO: Set the path variable to a local audio file path.
                     */
//                  path = "http://upload.wikimedia.org/wikipedia/commons/a/a9/Tromboon-sample.ogg";
//                  path = "http://www.robtowns.com/music/blind_willie.mp3";
                    path = "http://www.nch.com.au/acm/8k16bitpcm.wav";
                    if (path == "") {
                        // Tell the user to provide an audio file URL.
                        Toast
                                .makeText(
                                        MediaPlayerDemo_Audio.this,
                                        "Please edit MediaPlayer_Audio Activity, "
                                                + "and set the path variable to your audio file path."
                                                + " Your audio file must be stored on sdcard.",
                                        Toast.LENGTH_LONG).show();

                    }
                    mMediaPlayer = new MediaPlayer();
                    Uri tempUri = Uri.parse(path);
                    try {
                        mMediaPlayer.setDataSource(this, tempUri);
                    }
                    catch (IllegalStateException e) {
                        Log.d(TAG, "IllegalStateException: " + e.getMessage());
                    }
                    catch (IOException e) {
                        Log.d(TAG, "IOException: " + e.getMessage());
                    }
                    catch (IllegalArgumentException e) {
                        Log.d(TAG, "IllegalArgumentException: " + e.getMessage());
                    }
                    catch (SecurityException e) {
                        Log.d(TAG, "SecurityException: " + e.getMessage());
                    }
                    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mMediaPlayer.prepare();
                    mMediaPlayer.start();
                    break;
                case RESOURCES_AUDIO:
                    /**
                     * TODO: Upload a audio file to res/raw folder and provide
                     * its resid in MediaPlayer.create() method.
                     */
                    mMediaPlayer = MediaPlayer.create(this, R.raw.test_cbr);
                    mMediaPlayer.start();

            }
            tx.setText("Playing audio...");

        } catch (Exception e) {
            Log.e(TAG, "error: " + e.getMessage(), e);
        }

    }

我只是更改了定义要播放的文件路径的那 3 行,以及项目中的其他任何内容。好吧,只有 Mp3 文件会播放,WAV 和 OGG 都会产生和我的问题类似的异常。

还有人愿意尝试吗?我应该假设有一个错误吗?

于 2011-02-11T08:42:24.757 回答
0

我用 AudioEncoder.AMR_NB 编码的音频文件,文件可以在 3G 下播放,但不能在 Wifi 下播放,Mp3 文件可以全部播放。所以我猜文件格式会影响结果。

于 2013-04-25T06:16:19.957 回答