示例#1
0
        private void ClearAllTask(bool Downing)
        {
            if (Downing)
            {
                if (System.Windows.MessageBox.Show("清除全部正在下载内容?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    foreach (ApplicationBarIconButton button in ApplicationBar.Buttons)
                    {
                        button.IsEnabled = true;
                    }
                    return;
                }
                var deletedInfos = new List<DownInfo>(MyDownloading.Count);
                var deletedMedias = new List<MediaFileDownload>(Utils.MediaFileDownload.DownloadQueue.Count);
                foreach (DownInfo down in MyDownloading)
                {
                    foreach (MediaFileDownload downloader in Utils.MediaFileDownload.DownloadQueue)
                    {
                        if (down.VID == downloader.Tag as string)
                        {
                            downloader.Pause();
                            try
                            {
                                if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(downloader.PathName))
                                    IsolatedStorageFile.GetUserStoreForApplication().DeleteFile(downloader.PathName);
                            }
                            catch (IsolatedStorageException)
                            {
                                foreach (var info in deletedInfos)
                                    MyDownloading.Remove(info);
                                foreach (var media in deletedMedias)
                                    Utils.MediaFileDownload.Remove(media);
                                MessageBox.Show("删除失败,请稍后重试!");
                                return;
                            }
                            deletedMedias.Add(downloader);
                            break;
                        }
                    }
                    deletedInfos.Add(down);
                    DownFactory.DeleteRecord(down.VID);
                    LocalPlayFactory locFac = new LocalPlayFactory();
                    locFac.DeleteRecord(down.VID);
                }
                MyDownloading.Clear();
                Utils.MediaFileDownload.Clear();

                foreach (ApplicationBarIconButton button in ApplicationBar.Buttons)
                {
                    button.IsEnabled = true;
                }
            }
            else
            {
                if (System.Windows.MessageBox.Show("清除全部已下载内容?", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    foreach (ApplicationBarIconButton button in ApplicationBar.Buttons)
                    {
                        button.IsEnabled = true;
                    }
                    return;
                }
                foreach (DownInfo down in MyDownloaded)
                {
                    if (IsolatedStorageFile.GetUserStoreForApplication().FileExists(down.LocalPathName))
                    IsolatedStorageFile.GetUserStoreForApplication().DeleteFile(down.LocalPathName);
                    DownFactory.DeleteRecord(down.VID);
                    LocalPlayFactory locFac = new LocalPlayFactory();
                    locFac.DeleteRecord(down.VID);
                }
                MyDownloaded.Clear();

                foreach (ApplicationBarIconButton button in ApplicationBar.Buttons)
                {
                    button.IsEnabled = true;
                }
            }
        }
示例#2
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;
            }


        }
示例#3
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;
        }
示例#4
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;
                    }
                }
            }
        }
示例#5
0
        private void xPPvodWP7MediaElement_MediaEnded(object sender, PPTVWP7MediaPlayer.PPLiveRoutedEventArgs e)
        {
            _isPlayEnd = true;
            _isOver = true;
            if (_playLocalFile)
            {
                //
                LocalPlayFactory localFactory = new LocalPlayFactory();
                localFactory.UpdateRecord(_localFileId, xPPvodWP7MediaElement.Position.Seconds);
                if (NavigationService.CanGoBack)
                    NavigationService.GoBack();
                return;
            }
            SaveToDB(ProgramIndex);
            xPPvodWP7MediaElement.Stop();
            _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());

            _isAutoStop = true;
            PlayNextProgram();
        }
示例#6
0
        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            _timer.Stop();
            _timerOfControlBar.Stop();
            if (_playLocalFile)
            {
                xPPvodWP7MediaElement.Pause();
                if (xPPvodWP7MediaElement.CurrentState == MediaElementState.Paused || xPPvodWP7MediaElement.CurrentState == MediaElementState.Playing)
                {// 更新当前的播放位置                  

                    LocalPlayFactory localFacotry = new LocalPlayFactory();
                    localFacotry.UpdateRecord(_localFileId, (long)xPPvodWP7MediaElement.Position.TotalSeconds);
                }
                return;
            }
            LogManager.Ins.Log("开始退出执行DAC");
            if (xPPvodWP7MediaElement.CurrentState != MediaElementState.Stopped)
            {
                _playTime = (DateTime.Now - _beginPlaying).TotalSeconds;

                _playBufferCount = _allBufferCount - _dragBufferCount;
                PPTVData.Factory.DACPlayInfo playInfo = new PPTVData.Factory.DACPlayInfo();
                playInfo.castType = 3;
                playInfo.stopReason = 1;
                playInfo.isPlaySucceeded = _isPlaySucceeded ? 1 : 0;
                LogManager.Ins.Log("查Wifi开始");
                playInfo.connType = _connType;
                LogManager.Ins.Log("查Wifi结束");
                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 : "");


                if (ChannelDetailInfo != null && !_isAutoStop)
                    PPTVData.Factory.DACFactory.DACPlaying(playInfo, ChannelDetailInfo, Utils.Utils.GetClientVersion());
                _isAutoStop = false;
            }
            LogManager.Ins.Log("DAC完成");
            SetInfo(true);
            LogManager.Ins.Log("开始保存到数据库");
            if (xPPvodWP7MediaElement.CurrentState == MediaElementState.Paused || xPPvodWP7MediaElement.CurrentState == MediaElementState.Playing)
                SaveToDB(ProgramIndex);
            LogManager.Ins.Log("数据库保存完成");
            //if (_isBackPress)
            //    xPPvodWP7MediaElement.OriSource = "";

            ChannelDetailInfo = null;
            _currentPlayBitrate = null;
            LogManager.Ins.Log("清空Source");
        }