在android上玩媒体播放器的wav

时间:2015-10-19 14:32:12

标签: android audio android-mediaplayer

我尝试播放来自网络的wav文件。

                    MediaPlayer mediaPlayer = new MediaPlayer();
                    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

                    try {
                        mediaPlayer.setDataSource(url);
                        mediaPlayer.prepare();
                    } catch (IOException e) {
                        e.printStackTrace();
                        Log.e("SoundPlayerService", "Error preparing music");
                    }

                    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                        @Override
                        public void onPrepared(MediaPlayer mp) {
                            Log.d(Tag, "Audio is playing from: " + url);
                            mp.start();
                        }
                    });

但它没有播放任何东西。代码有什么问题?

1 个答案:

答案 0 :(得分:0)

您应该使用temp[,-c(1,2)][temp[, -c(1,2)] < 0] <- 0代替mediaPlayer.prepareAsync()