none
MediaElement_MediaEnded不触发 RRS feed

  • 问题

  • 我报告了音视频结束流,之后GetSampleAsync也不会再取了,但是我的播放器有些视频结束后可以触发MediaElement_MediaEnded,有些视频不触发,怎么回事呀?弄了一周,没弄出来,请哪位指点
    2013年9月12日 7:23

答案

  •  private void PositionTimerTick(object sender, EventArgs e)
            {
                TimeSpan span = this.mediaElement.Position;
                long totalSeconds = (long)span.TotalSeconds;
                this.progressBar.Value = span.TotalSeconds;

           
            }
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                IDictionary<string, string> queryString = this.NavigationContext.QueryString;

                if (queryString.ContainsKey("SourceURI"))
                {
                    mSourceURI = new Uri(queryString["SourceURI"], UriKind.RelativeOrAbsolute);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false, "FullScreenPlayer.OnNavigatedTo: SourceURI is not set.");
                    NavigationService.GoBack();
                }
                String url = "http的url链接";
              
               mDataBuffered = new DataBuffered(url);
                mMediaStream = new ReadPacket_Demux();
              
                try
                {
                   mediaElement.SetSource(mMediaStream);
                
                }
                catch (System.Exception ex)
                {
                    Debug.WriteLine("{0} exception caught here.", ex.GetType().ToString());
                    Debug.WriteLine(ex.Message);
               
                }
                mPositionTimer = new DispatcherTimer();

                mPositionTimer.Interval = TimeSpan.FromSeconds(1);
                mPositionTimer.Tick += new EventHandler(this.PositionTimerTick);
                mPositionTimer.Start();
                mediaElement.Play();
                //mediaElement.MediaEnded += new RoutedEventHandler(MediaElement_MediaEnded);
                base.OnNavigatedTo(e);
            }

            private void button_pause_Click(object sender, RoutedEventArgs e)
            {
                //读包线程挂起
                ReadPacket_Demux.mPlayer.pause();
                //silverlight挂起
                mediaElement.Pause();
            }

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                ReadPacket_Demux.mPlayer.start();
                mediaElement.Play();
            }
            //当媒体流已被验证和打开且已读取文件头时发生,获取媒体时长
            private void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
            {
                TimeSpan span = this.mediaElement.NaturalDuration.TimeSpan;
               
                 progressBar.Maximum = span.TotalSeconds;
                 SampleBuffer.mDuration = (int)span.TotalSeconds;
            }
            //当mediaElement播放完毕后触发
            private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
            {
                 mediaElement.Stop();
                          
                //释放buffer
                mMediaStream.DoCloseMedie();
                //释放api
                ReadPacket_Demux.mPlayer.release();
                ReadPacket_Demux.mPlayer = null;
                 
            }

    这是界面的简单代码,下面几行代码是最后一帧报告后,报告结束流

    //最后一帧,报告流结束信息
                    if (DataBuffered.mIsEndOfStream)
                    {                   
                        if (mSamples.Count == 0 && !mIsSeeking.isSeeking())                 
                        {
                            mEmptyAttributes[MediaSampleAttributeKeys.KeyFrameFlag] = Boolean.FalseString;

                            if (sampleAttributes == null)
                                sampleAttributes = mEmptyAttributes;
                            Debug.WriteLine("{0}silverlight read over", mMsd.Type.ToString());
                            mIsReportEnd = true;
                            return new MediaStreamSample(mMsd, null, 0, 0,0, sampleAttributes);
                        }
                    }


    2013年9月13日 1:12

全部回复

  • 最好贴上代码,这样怎么分析问题啊!
    2013年9月12日 8:55
  •  private void PositionTimerTick(object sender, EventArgs e)
            {
                TimeSpan span = this.mediaElement.Position;
                long totalSeconds = (long)span.TotalSeconds;
                this.progressBar.Value = span.TotalSeconds;

           
            }
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                IDictionary<string, string> queryString = this.NavigationContext.QueryString;

                if (queryString.ContainsKey("SourceURI"))
                {
                    mSourceURI = new Uri(queryString["SourceURI"], UriKind.RelativeOrAbsolute);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false, "FullScreenPlayer.OnNavigatedTo: SourceURI is not set.");
                    NavigationService.GoBack();
                }
                String url = "http的url链接";
              
               mDataBuffered = new DataBuffered(url);
                mMediaStream = new ReadPacket_Demux();
              
                try
                {
                   mediaElement.SetSource(mMediaStream);
                
                }
                catch (System.Exception ex)
                {
                    Debug.WriteLine("{0} exception caught here.", ex.GetType().ToString());
                    Debug.WriteLine(ex.Message);
               
                }
                mPositionTimer = new DispatcherTimer();

                mPositionTimer.Interval = TimeSpan.FromSeconds(1);
                mPositionTimer.Tick += new EventHandler(this.PositionTimerTick);
                mPositionTimer.Start();
                mediaElement.Play();
                //mediaElement.MediaEnded += new RoutedEventHandler(MediaElement_MediaEnded);
                base.OnNavigatedTo(e);
            }

            private void button_pause_Click(object sender, RoutedEventArgs e)
            {
                //读包线程挂起
                ReadPacket_Demux.mPlayer.pause();
                //silverlight挂起
                mediaElement.Pause();
            }

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                ReadPacket_Demux.mPlayer.start();
                mediaElement.Play();
            }
            //当媒体流已被验证和打开且已读取文件头时发生,获取媒体时长
            private void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
            {
                TimeSpan span = this.mediaElement.NaturalDuration.TimeSpan;
               
                 progressBar.Maximum = span.TotalSeconds;
                 SampleBuffer.mDuration = (int)span.TotalSeconds;
            }
            //当mediaElement播放完毕后触发
            private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
            {
                 mediaElement.Stop();
                          
                //释放buffer
                mMediaStream.DoCloseMedie();
                //释放api
                ReadPacket_Demux.mPlayer.release();
                ReadPacket_Demux.mPlayer = null;
                 
            }

    这是界面的简单代码,下面几行代码是最后一帧报告后,报告结束流

    //最后一帧,报告流结束信息
                    if (DataBuffered.mIsEndOfStream)
                    {                   
                        if (mSamples.Count == 0 && !mIsSeeking.isSeeking())                 
                        {
                            mEmptyAttributes[MediaSampleAttributeKeys.KeyFrameFlag] = Boolean.FalseString;

                            if (sampleAttributes == null)
                                sampleAttributes = mEmptyAttributes;
                            Debug.WriteLine("{0}silverlight read over", mMsd.Type.ToString());
                            mIsReportEnd = true;
                            return new MediaStreamSample(mMsd, null, 0, 0,0, sampleAttributes);
                        }
                    }


    2013年9月13日 1:12
  • 你好:

    推荐你把这个问题发布到Silverlight 技术论坛来获得更多帮助。


    Caillen
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2013年9月13日 6:11
    版主
  • 2013年9月13日 7:27