如何在Android Lollipop上通过https流式传输mp3文件?

时间:2015-07-15 19:05:02

标签: android android-mediaplayer audio-streaming

我有一个应用程序通过https协议从AWS服务器传输mp3文件。 它适用于Android 4.4设备,但不适用于Android 5.0+设备。

根据这篇文档Supported Media Formats,我无法理解是否通过http / https支持mp3。

这是我的代码:

private void playSong(String songPath, final ArtistSongData data) {
    if (currentVersionSupportLockScreenControls) {
        UpdateMetadata(data);
        remoteControlClient
                .setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
    }
    if (mp.isPlaying()) {
        mp.stop();
    }
    mp.reset();
    PlayerConstants.isMediaPlayerPrepared = false;
    try {
        mp.setDataSource(songPath);
        // mp.setDataSource("http://p48.ve.vc/data/48/32549/272565/Kede_Pind_Di_-_Jassi_Gill_-_Jassi_Gill_-_48Kbps_-_www.DjPunjab.Com.mp3");
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    // mp.setAudioStreamType(AudioStream.MODE_NORMAL);
    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mp.prepareAsync();
    mp.setOnPreparedListener(new OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer arg0) {
            // TODO Auto-generated method stub
            System.out.println("Music player prepared");
            mp.start();
            PlayerConstants.isMediaPlayerPrepared = true;
            System.out.println("starting now ...");
            timer = new Timer();
            timer.scheduleAtFixedRate(new MainTask(), 0, 100);
            if (PlayerConstants.isHomeShown == true) {
                HomeFragment.changeUI();
                HomeFragment.setSeekBAr(mp.getDuration());
            }
        }
    });

}

任何帮助将不胜感激。

由于

0 个答案:

没有答案