0

让我解释清楚:

  1. 我有一个名为“声音”的文件夹,并且有一些 .ogg 文件可以播放。
  2. 我使用Environment.getExternalStorageDirectory().getAbsolutePath() + mySoundsPath;.
  3. 我从该文件夹中获取了所有列表并将其保存到数组中:List<String> soundList;

我的问题是:

  1. 如何调用soundList我创建的声音以便它们都可以播放?
  2. 它是否需要解码(如图像,解码为位图)?

对不起我的语法。提前致谢。

4

2 回答 2

0

使用以下链接作为参考 http://developer.android.com/reference/android/media/MediaPlayer.html

您也可以尝试小代码示例

http://davanum.wordpress.com/2007/12/29/android-videomusic-player-sample-from-local-disk-as-well-as-remote-urls/

于 2012-11-29T07:19:44.067 回答
0

公共无效播放(字符串路径){count++; 播放文件=路径;

            //showNotification();
        new NotificationPanel(activity);


            if(mediaPlayer!=null && mediaPlayer.isPlaying()){
                Log.d("*****begin*****", "playing");
                stopPlaying();
                 Log.d("*****begin*****", "stoping");
              } else{
                 Log.d("*****begin*****", "nothing");
              }


            Uri myUri1 = Uri.parse(path);
            mediaPlayer = new MediaPlayer();
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

            try {
                mediaPlayer.setDataSource(activity, myUri1);            
            } catch (IllegalArgumentException e) {
                Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (SecurityException e) {
                Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (IllegalStateException e) {
                Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                mediaPlayer.prepare();
            } catch (IllegalStateException e) {
                Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(activity, "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
            }
            mediaPlayer.start();

        }

        private void stopPlaying() { 
            if (mediaPlayer != null) {
                mediaPlayer.stop();
                mediaPlayer.release();
                mediaPlayer = null;
           } 
        }
于 2015-05-26T11:45:21.220 回答