从firebase加载Mp3文件到我的Android应用程序

时间:2017-10-12 18:43:54

标签: android firebase load mp3 firebase-storage

我的应用将原始文件夹中的mp3加载到应用中 我需要从firebase存储加载这个mp3文件 我将所有这些mp3文件上传到firebase存储

我通过编写一些代码来遵循firebase手册编写,但我没有得到它。 请有人请编辑我的代码以从firebase加载mp3文件吗?

这是我的代码:

  convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            currentPosition = position;

            final AlertDialog.Builder popupBuilder = new AlertDialog.Builder(LessonWords.this);
            LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View convertView = layoutInflater.inflate(R.layout.player, null, false);
            Button next = (Button) convertView.findViewById(R.id.button2);
            Button pervious = (Button) convertView.findViewById(R.id.button);

            final ToggleButton play = (ToggleButton) convertView.findViewById(R.id.toggleButton);
            final Button close = (Button) convertView.findViewById(R.id.close);


            final Uri uriEN = Uri.parse("android.resource://" + getPackageName() + "/raw/th" + list.get(currentPosition).id);
            songPlayer = songPlayer.create(ctx, uriEN);

            play.setChecked(false);
            play.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {


                @Override
                public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
                    if (isChecked) {
                        play.setBackgroundResource(R.drawable.pause);
                        if (!songPlayer.isPlaying() && flag)
                            songPlayer.start();

                    } else {
                        play.setBackgroundResource(R.drawable.playbutton);
                        if (songPlayer.isPlaying())
                            songPlayer.pause();

                    }
                    songPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                        @Override
                        public void onCompletion(MediaPlayer mp) {


                            flag = false;
                        }
                    });


                }
            });
            close.setOnClickListener(new View.OnClickListener() {
                                         @Override
                                         public void onClick(View v) {finish();};

                                     }
            );
            next.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (currentPosition < list.size() - 1) {
                        currentPosition++;

                        songPlayer.release();

                        final Uri uriEN = Uri.parse("android.resource://" + getPackageName() + "/raw/th" + list.get(currentPosition).id);
                        songPlayer = songPlayer.create(ctx, uriEN);

                        songPlayer.start();
                        songPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {


                                flag = false;
                            }
                        });
                        play.setChecked(true);
                    }
                }
            });
            pervious.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (currentPosition > 0) {
                        currentPosition--;

                        songPlayer.release();

                        final Uri uriEN = Uri.parse("android.resource://" + getPackageName() + "/raw/th" + list.get(currentPosition).id);
                        songPlayer = songPlayer.create(ctx, uriEN);

                        songPlayer.start();
                        songPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {


                                flag = false;
                            }
                        });
                        play.setChecked(true);
                    }
                }
                    });

                    popupBuilder.setView(convertView);
                    popupBuilder.show();

                }
            });
    return convertView;
}
  }

0 个答案:

没有答案