コード例 #1
0
        private void xPPvodWP7MediaElement_MediaOpened(object sender, PPTVWP7MediaPlayer.PPLiveRoutedEventArgs e)
        {
            if (_playLocalFile)
            {
                // 接着从上次停止的地方接着观看

                LocalPlayFactory localFactory = new LocalPlayFactory();
                xPPvodWP7MediaElement.Position = TimeSpan.FromSeconds(localFactory.GetPosition(_localFileId));
                return;
            }
            _isPlaySucceeded = true;
            _prepareTime     = (DateTime.Now - _programBegin).TotalSeconds;
            _beginPlaying    = DateTime.Now;
            if (!_mediaIsOpened)
            {
                _mediaIsOpened = true;
                // seek 到以前的位置
                if (_openedToSeekPosition > 0)
                {
                    if (xPPvodWP7MediaElement.CanSeek)
                    {
                        xPPvodWP7MediaElement.Position = TimeSpan.FromSeconds(_openedToSeekPosition);
                        _openedToSeekPosition          = 0;
                    }
                }
            }
        }
コード例 #2
0
        private void xPPvodWP7MediaElement_CurrentStateChanged(object sender, PPTVWP7MediaPlayer.PPLiveRoutedEventArgs e)
        {
            switch (xPPvodWP7MediaElement.CurrentState)
            {
            case MediaElementState.AcquiringLicense:
                break;

            case MediaElementState.Buffering:
                _bufferingPosition = xPPvodWP7MediaElement.Position.TotalSeconds;
                SetInfo(true, "正在缓冲影片");
                SetControlBarStatus(false, true);
                break;

            case MediaElementState.Closed:
                _timer.Stop();
                break;

            case MediaElementState.Individualizing:
                break;

            case MediaElementState.Opening:
                SetInfo(true, "正在打开影片");
                BeginSetChannelToVideoHub(ChannelDetailInfo);
                break;

            case MediaElementState.Paused:
                SetControlBarStatus(false, true);
                break;

            case MediaElementState.Playing:
                //判断是否有播放过,如果有播放过 则从用户播放过的位置开始播放
                _isDrag = false;
                if (_isPlayDBPosition)
                {
                    if (_playLocalFile)
                    {
                        // 接着从上次停止的地方接着观看
                        LocalPlayFactory localFactory = new LocalPlayFactory();
                        xPPvodWP7MediaElement.Position = TimeSpan.FromSeconds(localFactory.GetPosition(_localFileId));
                    }
                    else
                    {
                        var playHistroy = PlayHistoryFactory.Instance.GetEntity(VID);
                        if (playHistroy != null)
                        {
                            _timer.Stop();
                            if (playHistroy.ProgramIndex == ProgramIndex)
                            {
                                xPPvodWP7MediaElement.Position = TimeSpan.FromSeconds(playHistroy.Position);
                            }
                        }
                    }
                }

                SetControlBarStatus();
                SetInfo(false);
                break;

            case MediaElementState.Stopped:
            {
                _playTime = (DateTime.Now - _beginPlaying).TotalSeconds;
                _timer.Stop();
                SetInfo(false);
                SetControlBarStatus(false, true);
                if (!_isAutoStop)
                {
                    _isAutoStop      = false;
                    _playBufferCount = _allBufferCount - _dragBufferCount;
                    PPTVData.Factory.DACPlayInfo playInfo = new PPTVData.Factory.DACPlayInfo();
                    playInfo.castType         = 3;
                    playInfo.stopReason       = 0;
                    playInfo.isPlaySucceeded  = _isPlaySucceeded ? 1 : 0;
                    playInfo.connType         = _connType;
                    playInfo.dragCount        = _dragCount;
                    playInfo.playBufferCount  = _playBufferCount;
                    playInfo.dragBufferTime   = _dragBufferTime;
                    playInfo.allBufferCount   = _allBufferCount;
                    playInfo.bufferTime       = _bufferTime;
                    playInfo.prepareTime      = _prepareTime;
                    playInfo.programSource    = _programSource;
                    playInfo.averageDownSpeed = _averageDownSpeed;
                    playInfo.playTime         = _playTime;

                    playInfo.mp4Name = Utils.Utils.UrlDecode(_currentPlayBitrate != null ? _currentPlayBitrate.Rid : "");

                    PPTVData.Factory.DACFactory.DACPlaying(playInfo, ChannelDetailInfo, Utils.Utils.GetClientVersion());
                }
            }
            break;

            default:
                break;
            }
            //xDebugTextBlock.Text = xPPvodWP7MediaElement.CurrentState.ToString();
            xPlayerControlBar.SetPlayerControlBarStuas(xPPvodWP7MediaElement.CurrentState);
            if (xPPvodWP7MediaElement.CurrentState != MediaElementState.Buffering)
            {
                _isDrag = false;
            }
        }
コード例 #3
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.NavigationMode != System.Windows.Navigation.NavigationMode.Back)
            {
                Utils.SocialUtils.ClearBackStack(this, "PlayPage.xaml");
                var response = Utils.SocialUtils.CreateBindResponse(this);
                if (!string.IsNullOrEmpty(response))
                {
                    xPopDialog.ContentText  = response;
                    xPopDialog.IsShowEnable = true;
                }
            }
            if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
            {
                if (NavigationContext.QueryString.ContainsKey("programIndex"))
                {
                    if (NavigationContext.QueryString["programIndex"] != null)
                    {
                        ProgramIndex = Convert.ToInt32(NavigationContext.QueryString["programIndex"]);
                    }
                }
            }
            _playLocalFile = false;
            if (NavigationContext.QueryString.ContainsKey("localplay"))
            {
                _playLocalFile = true;
            }

            // _playLocalFile = true;
            if (!_playLocalFile)
            {
                VID            = Convert.ToInt32(NavigationContext.QueryString["vid"]);
                _programSource = Convert.ToInt32(NavigationContext.QueryString["programSource"]);
                SetVarDefault();
            }
            else
            {
                SetVarDefault();
                _localFileId = NavigationContext.QueryString.ContainsKey("id") ?
                               NavigationContext.QueryString["id"] : "";
                LocalPlayFactory localFactory = new LocalPlayFactory();
                if (localFactory.GetPosition(_localFileId) == 0)
                {
                    localFactory.InsertRecord(_localFileId, 0);
                }
                _localFilePath = NavigationContext.QueryString.ContainsKey("path") ?
                                 NavigationContext.QueryString["path"] : "";
                _localFileTitle = NavigationContext.QueryString.ContainsKey("title") ?
                                  NavigationContext.QueryString["title"] : "";
                if (!System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication().FileExists(_localFilePath))
                {
                    MessageBox.Show("无法找到文件", "提示", MessageBoxButton.OK);
                    DownPage.DownFactory.DeleteRecord(_localFileId);
                    if (NavigationService.CanGoBack)
                    {
                        NavigationService.GoBack();
                    }
                    return;
                }
                xPPvodWP7MediaElement.Source     = _localFilePath;  // path;
                xPlayerControlBar.localFileTitle = _localFileTitle; // title;
            }
        }