Exemple #1
0
        private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            string video_name = null;
            if (NavigationContext.QueryString.TryGetValue("Video", out video_name))
            {
                StorageFolder videosFolder = KnownFolders.VideosLibrary;

                IReadOnlyList<StorageFile> fileList = await videosFolder.GetFilesAsync();
                IReadOnlyList<StorageFolder> folderList = await videosFolder.GetFoldersAsync();

                var count = fileList.Count + folderList.Count;
                foreach (StorageFile file in fileList)
                {
                    if (file.Name == video_name)
                    {
                        try {
                            path.Text = file.Path;
                            videoPlayer.Source = new Uri(file.Path, UriKind.Absolute);
                            video = file;
                            x = await video.Properties.GetVideoPropertiesAsync();
                            videoPlayer.Play();
                            //pbVideo.Maximum = (int)videoPlayer.NaturalDuration.TimeSpan.TotalSeconds;
                            changeProgressBar();
                        }
                        catch(Exception e1)
                        {
                            MessageBox.Show(e1.ToString());
                        }
                    }
                }
            }
        }
        private async void PlaylistView_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(StandardDataFormats.StorageItems))
            {
                var storageItems = await e.DataView.GetStorageItemsAsync();

                foreach (var storageItem in storageItems)
                {
                    var storageFile = storageItem as StorageFile;
                    System.Diagnostics.Debug.WriteLine(storageFile.ContentType);

                    if (AllowedMediaTypes.Contains(storageFile.ContentType, StringComparer.OrdinalIgnoreCase))
                    {
                        Windows.Storage.FileProperties.VideoProperties videoProperties = await storageFile.Properties.GetVideoPropertiesAsync();

                        TimeSpan duration = new RoundedTimeSpan(videoProperties.Duration.Ticks, 0).TimeSpan;

                        Item item = new Item()
                        {
                            Id           = Guid.NewGuid(),
                            FileName     = storageFile.DisplayName,
                            FilePath     = storageFile.Path,
                            FileDuration = duration
                        };

                        Playlist.Add(item);
                        RefreshCollectionTimes();
                    }
                }
            }
        }
Exemple #3
0
        public async Task GetVideo(string filename, string foldername, MediaElement mediaElement, bool wait)
        {
            try
            {
                StorageFolder folder;
                if (foldername == null)
                {
                    folder = await KnownFolders.VideosLibrary.GetFolderAsync("AppAssets");
                }
                else
                {
                    folder = await KnownFolders.VideosLibrary.GetFolderAsync("AppAssets\\" + foldername);
                }

                StorageFile file = await folder.GetFileAsync(filename);

                var stream = await file.OpenAsync(FileAccessMode.Read);

                mediaElement.Visibility = Visibility.Visible;
                mediaElement.SetSource(stream, file.ContentType);
                Windows.Storage.FileProperties.VideoProperties videoProperties = await file.Properties.GetVideoPropertiesAsync();

                int duration = Convert.ToInt32(videoProperties.Duration.TotalSeconds);
                if (wait == true)
                {
                    GetTimer.DispatcherTimerExtendOverwrite(duration + GetTimer.defaultIdleTime);
                }
                await Task.Delay(duration * 1000);

                return;
            }
            catch (Exception ex)
            {
                if (ex is FormatException)
                {
                    mediaElement.Visibility = Visibility.Collapsed;
                }
            }
        }