Silverlight MediaElement不再播放 [英] Silverlight MediaElement doesnt play again

查看:60
本文介绍了Silverlight MediaElement不再播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个媒体元素,我提供了一个来自微软翻译服务的来源。这是一个小问题因为它给了我一个wav文件。我使用WAVmss库来帮助我,它很有效,但有一点。它是第一次将文件加载到元素中时播放,但是当我第二次尝试播放它时它不会播放?回放代码不能简单:



I have a media element which I give a source I get from Microsofts translation service. This is a slight problem because it gives me a wav file. I used the WAVmss library to help me and it works great, but for one thing. It plays the first time I load the file into the element, but when I try and play it a second time it doesn''t play? The playback code could not be simpler:

private void Play()
        {
            mediaElement.Stop();
            mediaElement.Position = TimeSpan.Zero;
            mediaElement.Play();
        }





我已调试过。 Position属性确实设置为零,当我再次点击它后闯入它的位置已经移动到最后。



想法?



I have debugged. The Position property does get set to zero, ,and when I break in after clicking it again its position has moved to the end.

An ideas?

推荐答案

尝试:

Try:
if (mediaElement.CurrentState == MediaElementState.Playing)
                {
                    mediaElement.Pause();
                }
                else
                {
                    if (mediaElement.CurrentState == MediaElementState.Paused)
                    {
                        if (mediaElement.Position == mediaElement.NaturalDuration.TimeSpan)
                        {
                            mediaElement.Position = new TimeSpan(0);
                        }
                        mediaElement.Play();
                    }
                 }


我遇到了同样的问题,感谢Gilles Khouzam 快速回复问题已经解决。



好的,我发现了问题.SeekAsync的实现,流中的位置发生了变化但是块中的剩余计数没有。在WaveMediaStreamSource.cs中,查找SeekAsync方法并将代码更改为此(添加MoveToChunkOffest行):



I had the same issue and thanks to Gilles Khouzam quick response the problem has been solved.

"Ok, I found the issue. The implementation of SeekAsync, the position in the stream was changed but the remaining count in the chunk was not. In WaveMediaStreamSource.cs, look for the SeekAsync method and change the code to this (add the MoveToChunkOffest line):"

this.currentPosition = this.wavParser.WaveFormatEx.BufferSizeFromAudioDuration( seekToTime ) + this.startPosition;
this.wavParser.MoveToChunkOffset( ( uint ) this.wavParser.WaveFormatEx.BufferSizeFromAudioDuration( seekToTime ) );
this.currentTimeStamp = seekToTime;
ReportSeekCompleted( seekToTime );


这篇关于Silverlight MediaElement不再播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆