从在线网址播放歌曲不适用于http,但适用于https

时间:2018-08-03 09:55:25

标签: android android-mediaplayer

当我正在做一个应用程序时,我将从网上获取歌曲的URL并在移动设备中播放它,当我尝试使用具有https url的示例中给出的URL时,它将起作用

但是从服务器上获取网址时,它不包含https,所以它没有播放歌曲,我不知道这是谁能帮助我

String AudioURL =“ https://www.ssaurel.com/tmp/mymusic.mp3”;

这是我目前使用的网址

String AudioURL =“ http://www.madhapadal.com/Audio/Nesam/02 Nee Oravadu.mp3”;

这是我在android中无法播放的实际网址

这是代码

@Override
    public void onClick(View v) {
        if (v.getId() == R.id.ButtonTestPlayPause) {

            try {
//                mediaPlayer = MediaPlayer.create(this, Uri.parse(AudioURL));
                mediaPlayer.setDataSource(AudioURL); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source
                mediaPlayer.setLooping(true);
                mediaPlayer.prepare(); // you must call this method after setup the datasource in setDataSource method. After calling prepare() the instance of MediaPlayer starts load data from URL to internal buffer.
            } catch (Exception e) {
                e.printStackTrace();
            }

            mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the song length in milliseconds from URL

            if (!mediaPlayer.isPlaying()) {
                String totalTime = milliSecondsToTimer(mediaPlayer.getDuration());
                mTxtTotalTime.setText(totalTime);
                mediaPlayer.start();
                buttonPlayPause.setImageResource(R.drawable.ic_pause_circle_outline_black_24dp);
            } else {
                mediaPlayer.pause();
                buttonPlayPause.setImageResource(R.drawable.ic_play);
            }

            primarySeekBarProgressUpdater();
        }
    }

请帮助我

预先感谢

0 个答案:

没有答案