1

我目前正在开发一个网络广播应用程序,如果用户按下暂停/停止键,流应该停止,当然,当他再次按下播放时,流应该继续。

我遇到的问题是, player.Stop() 只会暂停曲目。如果再次按下继续,前 5 秒不是从流中读取,而是从缓冲区中读取,然后它会在几秒钟内不播放声音,然后再次开始从流中读取。

这对于网络广播应用程序来说是致命的。我该如何解决?或者我怎样才能删除缓冲区?

    protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
    {
        switch (playState)
        {
            case PlayState.TrackReady:
                player.Play();
                break;
            case PlayState.Stopped:
                player.Stop();
                break;
            case PlayState.Paused:
                player.Stop();
                break; 
        }

        NotifyComplete();
    }
4

2 回答 2

2

好吧..只是让你们知道,这就是我所做的。我不知道是否有更好的方法,但这对我有用:

        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
    {
        switch (playState)
        {
            case PlayState.Stopped:
                track.BeginEdit();
                track.Tag = track.Source.OriginalString;
                track.Source = new Uri("http://127.0.0.1", UriKind.Absolute);
                track.EndEdit();

                player.Track = track;
                break;


        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
    {
        switch (action)
        {
            case UserAction.Play:
                if (player.PlayerState != PlayState.Playing)
                {
                    try
                    {
                        player.Play();
                    }
                    catch(Exception)
                    {
                        track.BeginEdit();
                        track.Source = new Uri(player.Track.Tag, UriKind.Absolute);
                        track.EndEdit();

                        player.Track = track;
                        player.Play();
                    }
                }
                break;
            case UserAction.Stop:
            case UserAction.Pause:
                if (player.Track.Source.OriginalString != "http://127.0.0.1/")
                {
                    player.Stop();
                }
                break;
于 2012-02-07T12:36:47.340 回答
0

How about ditching everything when you stop, and newing it up again when playback starts again? It seems the functionality you are using is more suited to pausing static content. Pause doesn't make much sense with radio.

于 2012-02-01T15:19:14.253 回答