private async void SendFileExecute()
        {
            if (MediaLibrary.SelectedCount > 0)
            {
                foreach (var storage in MediaLibrary.Where(x => x.IsSelected))
                {
                    await SendFileAsync(storage.File, storage.Caption);
                }

                return;
            }

            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add("*");

            var files = await picker.PickMultipleFilesAsync();

            if (files != null && files.Count > 0)
            {
                foreach (var storage in files)
                {
                    await SendFileAsync(storage, null);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取指定的story.
        /// </summary>
        /// <param name="storyName">story名称.</param>
        /// <param name="userStore">如果参数为null, 创建一个新的.</param>
        internal static void ReadStoryFile(string storyName, IsolatedStorageFile userStore = null)
        {
            if (userStore == null)
            {
                userStore = IsolatedStorageFile.GetUserStoreForApplication();
            }
            using (IsolatedStorageFileStream fileStream = userStore.OpenFile(storyName + ".xml", System.IO.FileMode.Open))
            {
                XDocument xdoc            = XDocument.Load(fileStream);
                var       picturesLibrary = new MediaLibrary().Pictures;

                // Load all photos.
                foreach (XElement photoElement in xdoc.Root.Elements())
                {
                    try
                    {
                        Photo photo = new Photo()
                        {
                            Name = photoElement.Attribute("Name").Value,
                        };
                        string photoDurationString = photoElement.Attribute("PhotoDuration").Value;
                        int    photoDuration       = int.Parse(photoDurationString);
                        photo.PhotoDuration = TimeSpan.FromSeconds(photoDuration);
                        XElement transitionElement = photoElement.Element("Transition");
                        if (transitionElement != null)
                        {
                            photo.Transition = TransitionBase.Load(photoElement.Element("Transition"));
                        }
                        Picture picture = picturesLibrary.Where(p => p.Name == photo.Name).FirstOrDefault();
                        if (picture == null)
                        {
                            // 如果找不到原文件,可能已经被删除了
                            // TODO: 我们需要记录错误吗? 我们是继续下一个图片还是抛出异常?
                            continue;
                        }
                        photo.ThumbnailStream = picture.GetThumbnail();
                        App.MediaCollection.Add(photo);
                    }
                    catch
                    {
                        // TODO: 我们需要记录错误吗? 我们是继续下一个图片还是抛出异常?
                        continue;
                    }
                }
            }
        }
        private async void SendMediaExecute()
        {
            if (MediaLibrary.SelectedCount > 0)
            {
                if (Settings.IsSendGrouped && MediaLibrary.SelectedCount > 1)
                {
                    var items = MediaLibrary.Where(x => x.IsSelected).ToList();
                    var group = new List <StorageMedia>(Math.Min(items.Count, 10));

                    foreach (var item in items)
                    {
                        group.Add(item);

                        if (group.Count == 10)
                        {
                            await SendGroupedAsync(group);

                            group = new List <StorageMedia>(Math.Min(items.Count, 10));
                        }
                    }

                    if (group.Count > 0)
                    {
                        await SendGroupedAsync(group);
                    }
                }
                else
                {
                    foreach (var storage in MediaLibrary.Where(x => x.IsSelected))
                    {
                        if (storage is StoragePhoto photo)
                        {
                            var storageFile = await photo.GetFileAsync();
                            await SendPhotoAsync(storageFile, storage.Caption, storage.IsForceFile, storage.Ttl);
                        }
                        else if (storage is StorageVideo video)
                        {
                            await SendVideoAsync(storage.File, storage.Caption, video.IsMuted, storage.IsForceFile, storage.Ttl, await video.GetEncodingAsync(), video.GetTransform());
                        }
                    }
                }

                return;
            }

            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.AddRange(Constants.MediaTypes);

            var files = await picker.PickMultipleFilesAsync();

            if (files != null && files.Count > 0)
            {
                var storages = new ObservableCollection <StorageMedia>();

                foreach (var file in files)
                {
                    var storage = await StorageMedia.CreateAsync(file, true);

                    if (storage != null)
                    {
                        storages.Add(storage);
                    }
                }

                SendMediaExecute(storages, storages[0]);
            }
        }
Ejemplo n.º 4
0
        private async void SendFileExecute(StorageFile file)
        {
            if (MediaLibrary.SelectedCount > 0)
            {
                foreach (var storage in MediaLibrary.Where(x => x.IsSelected))
                {
                    await SendFileAsync(storage.File, storage.Caption);
                }

                return;
            }

            ObservableCollection <StorageFile> storages = null;

            if (file == null)
            {
                var picker = new FileOpenPicker();
                picker.ViewMode = PickerViewMode.Thumbnail;
                picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                picker.FileTypeFilter.Add("*");

                var files = await picker.PickMultipleFilesAsync();

                if (files != null)
                {
                    storages = new ObservableCollection <StorageFile>(files);
                }
            }
            else
            {
                storages = new ObservableCollection <StorageFile> {
                    file
                };
            }

            if (storages != null && storages.Count > 0)
            {
                foreach (var storage in storages)
                {
                    //var props = await storage.Properties.GetVideoPropertiesAsync();
                    //var width = props.Width;
                    //var height = props.Height;
                    //var x = 0d;
                    //var y = 0d;

                    //if (width > height) {
                    //    x = (width - height) / 2;
                    //    width = height;
                    //}

                    //if (height > width)
                    //{
                    //    y = (height - width) / 2;
                    //    height = width;
                    //}

                    //var transform = new VideoTransformEffectDefinition();
                    //transform.CropRectangle = new Windows.Foundation.Rect(x, y, width, height);
                    //transform.OutputSize = new Windows.Foundation.Size(240, 240);

                    //var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
                    //profile.Video.Width = 240;
                    //profile.Video.Height = 240;
                    //profile.Video.Bitrate = 300000;

                    //await SendVideoAsync(storage, null, true, transform, profile);
                    await SendFileAsync(storage, null);
                }
            }
        }
Ejemplo n.º 5
0
        private async void SendMediaExecute(ObservableCollection <StorageMedia> media)
        {
            if (MediaLibrary.SelectedCount > 0)
            {
                foreach (var storage in MediaLibrary.Where(x => x.IsSelected))
                {
                    if (storage is StoragePhoto photo)
                    {
                        await SendPhotoAsync(storage.File, storage.Caption, storage.TTLSeconds);
                    }
                    else if (storage is StorageVideo video)
                    {
                        await SendVideoAsync(storage.File, storage.Caption, false, await video.GetEncodingAsync());
                    }
                }

                return;
            }



            ObservableCollection <StorageMedia> storages = media;

            if (media == null)
            {
                var picker = new FileOpenPicker();
                picker.ViewMode = PickerViewMode.Thumbnail;
                picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                picker.FileTypeFilter.AddRange(Constants.MediaTypes);

                var files = await picker.PickMultipleFilesAsync();

                if (files != null)
                {
                    storages = new ObservableCollection <StorageMedia>();

                    foreach (var file in files)
                    {
                        if (file.ContentType.Equals("video/mp4"))
                        {
                            storages.Add(await StorageVideo.CreateAsync(file, true));
                        }
                        else
                        {
                            storages.Add(new StoragePhoto(file)
                            {
                                IsSelected = true
                            });
                        }
                    }
                }
            }
            //else
            //{
            //    storages = new ObservableCollection<StorageMedia>(media);
            //}

            if (storages != null && storages.Count > 0)
            {
                var dialog = new SendPhotosView {
                    ViewModel = this, Items = storages, SelectedItem = storages[0], IsTTLEnabled = _peer is TLInputPeerUser
                };
                var dialogResult = await dialog.ShowAsync();

                TextField.FocusMaybe(FocusState.Keyboard);

                if (dialogResult == ContentDialogBaseResult.OK)
                {
                    foreach (var storage in dialog.Items.Where(x => x.IsSelected))
                    {
                        if (storage is StoragePhoto photo)
                        {
                            await SendPhotoAsync(storage.File, storage.Caption, storage.TTLSeconds);
                        }
                        else if (storage is StorageVideo video)
                        {
                            await SendVideoAsync(storage.File, storage.Caption, false, await video.GetEncodingAsync());
                        }
                    }
                }
            }
        }