コード例 #1
0
            public void RemovesIdsThatNoLongerExist()
            {
                var source = Substitute.For <ISource>();

                source.Name.Returns(new SourceName("SourceName"));

                var sourceData = Substitute.For <ISourceData>();

                sourceData.Source.Returns(source);

                MediaItem.GetAllSourceData().Returns(new[] { sourceData });

                PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                       Arg.Any <Action <string> >())
                .Returns(m =>
                {
                    var r = m.Arg <MetadataResult <Series> >();

                    r.Item.Name        = "Name";
                    r.Item.ProviderIds = new Dictionary <string, string> {
                        { "SourceName", "3" }
                    };

                    return(r);
                });

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsRight.Should().BeTrue();
                result.IfRight(r =>
                {
                    r.EmbyMetadataResult.Item.ProviderIds.Should().NotContainKey("SourceName");
                    r.EmbyMetadataResult.Item.ProviderIds.Should().NotContainValue("3");
                });
            }
コード例 #2
0
        public void Setup()
        {
            PropertyMappings = Substitute.For <IPropertyMappingCollection>();
            PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                   Arg.Any <Action <string> >())
            .Returns(x => x.Arg <MetadataResult <Series> >());
            PropertyMappings.GetEnumerator()
            .Returns(new IPropertyMapping[]
            {
                new PropertyMapping <AniDbSeriesData, MetadataResult <Series>, string>("Name", s => s.Item.Name,
                                                                                       (s, t) => t.Item.Name = "Name", SourceNames.AniDb)
            }.AsEnumerable().GetEnumerator());

            PluginConfiguration = Substitute.For <IPluginConfiguration>();

            var embyItemData = Substitute.For <IEmbyItemData>();

            embyItemData.Language.Returns("en");

            _sources = new TestSources();
            var aniDbSourceData = new SourceData <AniDbSeriesData>(_sources.AniDb, 33, new ItemIdentifier(33, 1, "Name"),
                                                                   new AniDbSeriesData());

            MediaItem = Substitute.For <IMediaItem>();
            MediaItem.GetAllSourceData().Returns(new ISourceData[] { aniDbSourceData });
            MediaItem.GetDataFromSource(null).ReturnsForAnyArgs(aniDbSourceData);
            MediaItem.EmbyData.Returns(embyItemData);

            MediaItemType = new MediaItemType <Series>("Series", (c, l) => PropertyMappings);
        }
コード例 #3
0
        public static string GetMediaIcon(MediaItemType type)
        {
            string mediaIconPath = String.Empty;

            switch (type)
            {
            case MediaItemType.Undefined:
                mediaIconPath = "../Resources/MediaItemIcons/small_unknown_data_icon.png";
                break;

            case MediaItemType.Text:
                mediaIconPath = "../Resources/MediaItemIcons/small_text_icon.png";
                break;

            case MediaItemType.Picture:
                mediaIconPath = "../Resources/MediaItemIcons/small_photo_icon.png";
                break;

            case MediaItemType.Audio:
                mediaIconPath = "../Resources/MediaItemIcons/small_music_icon.png";
                break;

            case MediaItemType.Video:
                mediaIconPath = "../Resources/MediaItemIcons/small_video_icon.png";
                break;

            default:
                Debug.Assert(false, "Unknown media type");
                break;
            }
            return(mediaIconPath);
        }
コード例 #4
0
        private Task <OperationResult <LibraryMediaItem> > GetLastSavedMediaItem(MediaItemType itemType)
        {
            var tcs = new TaskCompletionSource <OperationResult <LibraryMediaItem> >();

            var fetchOptions = new PHFetchOptions();

            fetchOptions.SortDescriptors = new NSSortDescriptor[] { new NSSortDescriptor("creationDate", false) };
            var fetchResult = PHAsset.FetchAssets(itemType == MediaItemType.Video ? PHAssetMediaType.Video : PHAssetMediaType.Image, fetchOptions);
            var phAsset     = fetchResult?.firstObject as PHAsset;

            if (phAsset != null)
            {
                PHImageManager.DefaultManager.RequestAvAsset(phAsset, null, (asset, audioMix, info) =>
                {
                    var urlAsset = asset as AVUrlAsset;
                    tcs.SetResult(OperationResult <LibraryMediaItem> .AsSuccess(new LibraryMediaItem(phAsset.LocalIdentifier, urlAsset.Url.AbsoluteString)));
                });
            }
            else
            {
                tcs.SetResult(OperationResult <LibraryMediaItem> .AsFailure("Could not retrieve last asset"));
            }

            return(tcs.Task);
        }
コード例 #5
0
            public void AppliesPropertyMappings()
            {
                MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                PropertyMappings.Received(1)
                .Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                       Arg.Any <Action <string> >());
            }
コード例 #6
0
        public MediaItem(string id)
        {
            BuildExceptions.NotNullNotEmpty(id, "id");

            _itemId   = id;
            _useMap   = String.Empty;
            _itemType = MediaItemType.Image;
            _itemUnit = MediaSizeUnit.None;
        }
コード例 #7
0
        private Task <OperationResult> GetMediaItem(string destinationPath, MediaItemType mediaItemType, UIImagePickerControllerSourceType sourceType)
        {
            var tcs = new TaskCompletionSource <OperationResult>();

            var picker = new ExtendedUIImagePickerController();

            picker.PreferredOrientation = UIApplication.SharedApplication.StatusBarOrientation;
            if (mediaItemType == MediaItemType.Video)
            {
                picker.VideoQuality = UIImagePickerControllerQualityType.At1280x720;
            }
            picker.SourceType = sourceType;
            var typeString = mediaItemType == MediaItemType.Video ? "public.movie" : "public.image";

            picker.MediaTypes = new string[] { typeString };

            picker.Canceled += (object sender, EventArgs e) =>
            {
                tcs.SetResult(OperationResult.AsCancel());
                picker.DismissViewController(true, null);
            };
            picker.FinishedPickingMedia += (object sender, UIImagePickerMediaPickedEventArgs e) =>
            {
                picker.DismissViewController(true, () =>
                {
                    NSUrl mediaURl = null;

                    if (e.MediaUrl != null)
                    {
                        mediaURl = e.MediaUrl;
                        File.Copy(mediaURl.Path, destinationPath, true);
                        tcs.SetResult(OperationResult.AsSuccess());
                    }
                    else
                    {
                        var originalImage = e.OriginalImage;
                        var imageData     = originalImage.AsJPEG();

                        NSError err = null;

                        if (imageData.Save(destinationPath, false, out err))
                        {
                            tcs.SetResult(OperationResult.AsSuccess());
                        }
                        else
                        {
                            tcs.SetResult(OperationResult.AsFailure(err.LocalizedDescription));
                        }
                    }
                });
            };

            NavigationHelper.GetActiveViewController().PresentViewController(picker, true, null);

            return(tcs.Task);
        }
コード例 #8
0
            public void NoLibrarySourceData_ReturnsFailure()
            {
                MediaItem.GetAllSourceData().Returns(new ISourceData[] { });
                MediaItem.GetDataFromSource(null).ReturnsForAnyArgs(Option <ISourceData> .None);

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsLeft.Should().BeTrue();
                result.IfLeft(r => r.Reason.Should().Be("No data returned by library structure source"));
            }
コード例 #9
0
ファイル: Medias.cs プロジェクト: mbatest/Video
 /// <summary>
 /// Creates a mediaItem of a specific type
 /// </summary>
 /// <param name="c"></param>
 /// <param name="mdType"></param>
 public MediaItem(MediaItem c, MediaItemType mdType)
 {
     mediaFile    = c.mediaFile;
     startInMedia = c.startInMedia;
     endInMedia   = c.endInMedia;
     startOnTrack = c.startOnTrack;
     endOnTrack   = c.endOnTrack;
     mediaType    = mdType;
     Comment      = c.Comment;
 }
コード例 #10
0
ファイル: MediaFolder.cs プロジェクト: mattweb28/pspplayer
        public IMediaItem CreateSymbolicLink(string name, MediaItemType type)
        {
            if (_device.IsReadOnly == true)
            {
                return(null);
            }

            // TODO: Support creation of symbolic links (may be hard on native fs)
            throw new NotImplementedException();
        }
コード例 #11
0
            public void NoNameMappingForLibrarySourceData_ReturnsFailure()
            {
                PropertyMappings.GetEnumerator()
                .Returns(Enumerable.Empty <IPropertyMapping>().GetEnumerator());

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsLeft.Should().BeTrue();
                result.IfLeft(r => r.Reason.Should().Be("No value for Name property mapped from library source"));
            }
コード例 #12
0
        public static async Task <bool> ShareMediaItem(this DependencyObject page, object mediaItem, MediaItemType type)
        {
            MediaType           = type;
            MediaItem           = mediaItem;
            filesToShare        = new List <IStorageItem>();
            dataTransferManager = DataTransferManager.GetForCurrentView();

            dataTransferManager.DataRequested += ShareHandler;

            return(await PrepareFiles(mediaItem, type));
        }
コード例 #13
0
            public void AppliesPropertyMappingsForIdentifierOnlySourceData()
            {
                var identifierOnlySourceData = new IdentifierOnlySourceData(_sources.AniDb, 33, new ItemIdentifier(33, 1, "Name"));

                MediaItem = Substitute.For <IMediaItem>();
                MediaItem.GetAllSourceData().Returns(new ISourceData[] { identifierOnlySourceData });

                MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                PropertyMappings.Received(1)
                .Apply(Arg.Is <IEnumerable <object> >(e => e.Contains(identifierOnlySourceData)), Arg.Any <MetadataResult <Series> >(),
                       Arg.Any <Action <string> >());
            }
コード例 #14
0
            public void NameNotMapped_ReturnsFailure(string name)
            {
                PropertyMappings.GetEnumerator()
                .Returns(new IPropertyMapping[]
                {
                    new PropertyMapping <AniDbSeriesData, MetadataResult <Series>, string>("Name", s => s.Item.Name,
                                                                                           (s, t) => t.Item.Name = name, SourceNames.AniDb)
                }.AsEnumerable().GetEnumerator());

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsLeft.Should().BeTrue();
                result.IfLeft(r => r.Reason.Should().Be("Property mapping failed for the Name property"));
            }
コード例 #15
0
 public MediaItem(MediaItem source)
     : base(source)
 {
     _itemId       = source._itemId;
     _itemPath     = source._itemPath;
     _altText      = source._altText;
     _itemType     = source._itemType;
     _itemUnit     = source._itemUnit;
     _itemWidth    = source._itemWidth;
     _itemHeight   = source._itemHeight;
     _useMap       = source._useMap;
     _imageMap     = source._imageMap;
     _resolveLinks = source._resolveLinks;
 }
コード例 #16
0
        public static MediaItemType GetTypeFromString(string typeString)
        {
            MediaItemType resolvedType = MediaItemType.Undefined;

            try
            {
                resolvedType = (NedEngine.MediaItemType)Enum.Parse(typeof(NedEngine.MediaItemType), typeString, true);
            }
            catch (ArgumentException)
            {
                System.Diagnostics.Debug.WriteLine("Library parse error: Could not parse item type, setting as Undefined");
            }
            return(resolvedType);
        }
        public void GetEnterprise_ReturnsSingleEnterprise()
        {
            //Arrange                           --Is there an easier way?
            MediaItemType mediaItemType = new MediaItemType {
                Id = 25, Name = "newMediaItemType"
            };
            MediaItem mediaItem = new MediaItem {
                Id = 20, Name = "newMediaItem", PlaceId = 15, MediaItemType = mediaItemType
            };
            Place place = new Place {
                Id = 15, Name = "newPlace", Description = "desc", ParticipantId = 10, MediaItems = new List <MediaItem>()
                {
                    mediaItem
                }
            };
            PathPoint pathPoint = new PathPoint {
                Id = 2, SequenceNumber = 3, Latitude = 2, Longitude = 3
            };
            Participant participant = new Participant {
                Id = 10, Name = "newParticipant", EnterpriseId = 5, Places = new List <Place>()
                {
                    place
                }, PathPoints = new List <PathPoint> {
                    pathPoint
                }
            };
            Enterprise enterprise = new Enterprise {
                Id = 5, Name = "Enterprise1", Password = "******", CoverImageURL = "myimage.com", ModifiedUTC = DateTime.UtcNow, Participants = new List <Participant>()
                {
                    participant
                }
            };

            _fakeContext.EnterpriseList.Add(enterprise);

            _target.Request = new HttpRequestMessage();
            _target.Request.Headers.Add("Authorization", "abc");

            //Act
            var response = _target.Get(5);

            //Assert
            response.Participants.First()
            .Places.First()
            .MediaItems.First().Name.Should().Be("newMediaItem");
            response.Participants.First().Places.First().Description.Should().Be("desc");
            response.Participants.First().PathPoints.First().Latitude.Should().Be(2);
        }
コード例 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaItem"/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        public MediaItem(MediaItemModel model, IValidator <MediaItem> validator, IMessenger messenger)
            : base(model, validator, messenger)
        {
            _location      = model.Location;
            _description   = model.Description;
            _title         = model.Title;
            _sequence      = model.Sequence;
            _duration      = TimeSpan.FromTicks(model.Duration);
            _privacyStatus = (PrivacyStatus)model.PrivacyStatus;
            _mediaItemType = (MediaItemType)model.MediaItemType;
            _createdBy     = model.CreatedBy;
            _createdOn     = model.CreatedOn;
            _updatedBy     = model.UpdatedBy;
            _updatedOn     = model.UpdatedOn;

            Validate();
        }
        public virtual void Setup()
        {
            PluginConfiguration = Substitute.For <IPluginConfiguration>();

            MediaItemBuilder = Substitute.For <IMediaItemBuilder>();
            MediaItemBuilder.BuildMediaItemAsync(Arg.Any <IMediaItem>())
            .Returns(x => Right <ProcessFailedResult, IMediaItem>(x.Arg <IMediaItem>()));

            MediaItemType = Substitute.For <IMediaItemType <Series> >();
            MediaItemType.CreateMetadataFoundResult(PluginConfiguration, Arg.Any <IMediaItem>(), Arg.Any <ILogManager>())
            .Returns(x => Right <ProcessFailedResult, IMetadataFoundResult <Series> >(new MetadataFoundResult <Series>(
                                                                                          x.Arg <IMediaItem>(), new MetadataResult <Series>
            {
                Item = new Series()
            })));

            Processor = new MediaItemProcessor(PluginConfiguration, MediaItemBuilder, new ConsoleLogManager());
        }
コード例 #20
0
            public void NameIsMapped_ReturnsResultWithHasMetadataToTrue()
            {
                PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                       Arg.Any <Action <string> >())
                .Returns(m =>
                {
                    var r = m.Arg <MetadataResult <Series> >();

                    r.Item.Name = "Name";

                    return(r);
                });

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsRight.Should().BeTrue();
                result.IfRight(r => r.EmbyMetadataResult.HasMetadata.Should().BeTrue());
            }
コード例 #21
0
            public void AddsProviderIdsForNonAdditionalSources()
            {
                var source = Substitute.For <ISource>();

                source.Name.Returns(new SourceName("SourceName"));

                var additionalSource = source.ForAdditionalData();

                var sourceData = Substitute.For <ISourceData>();

                sourceData.Id.Returns(3);
                sourceData.Source.Returns(source);

                var additionalSourceData = Substitute.For <ISourceData>();

                additionalSourceData.Id.Returns(3);
                additionalSourceData.Source.Returns(additionalSource);

                MediaItem.GetAllSourceData().Returns(new[] { sourceData });

                PropertyMappings.Apply(Arg.Any <IEnumerable <object> >(), Arg.Any <MetadataResult <Series> >(),
                                       Arg.Any <Action <string> >())
                .Returns(m =>
                {
                    var r = m.Arg <MetadataResult <Series> >();

                    r.Item.Name = "Name";

                    return(r);
                });

                var result = MediaItemType.CreateMetadataFoundResult(PluginConfiguration, MediaItem, new ConsoleLogManager());

                result.IsRight.Should().BeTrue();
                result.IfRight(r =>
                {
                    r.EmbyMetadataResult.Item.ProviderIds.Should().ContainKey("SourceName");
                    r.EmbyMetadataResult.Item.ProviderIds.Should().ContainValue("3");
                });
            }
コード例 #22
0
        private static async Task <bool> PrepareFiles(object mediaItem, MediaItemType type)
        {
            if (type == MediaItemType.Song)
            {
                if (mediaItem.GetType() == typeof(Song))
                {
                    Song        song = mediaItem as Song;
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song.SongURI);

                    if (file == null)
                    {
                        filesToShare = null;
                        return(false);
                    }

                    filesToShare.Add(file);
                }
                else
                {
                    // É LISTA DE STRING!!
                    List <string> list = mediaItem as List <string>;

                    foreach (string path in list)
                    {
                        StorageFile file = await StorageFile.GetFileFromPathAsync(path);

                        if (file != null)
                        {
                            filesToShare.Add(file);
                        }
                    }
                }
            }
            else if (type == MediaItemType.Album)
            {
                Album album = mediaItem as Album;

                var songs = CollectionHelper.GetSongsByAlbumID(album.AlbumID);
                foreach (Song song in songs)
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song.SongURI);

                    if (file != null)
                    {
                        filesToShare.Add(file);
                    }
                }
            }
            else if (type == MediaItemType.Artist)
            {
                Artist artist = mediaItem as Artist;

                var songs = CollectionHelper.GetSongsByArtist(artist.Name);
                foreach (Song song in songs)
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song.SongURI);

                    if (file != null)
                    {
                        filesToShare.Add(file);
                    }
                }
            }
            else if (type == MediaItemType.Playlist)
            {
                Playlist playlist = mediaItem as Playlist;

                foreach (string song in playlist.Songs)
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song);

                    if (file != null)
                    {
                        filesToShare.Add(file);
                    }
                }
            }

            if (filesToShare.Count == 0)
            {
                return(false);
            }

            DataTransferManager.ShowShareUI();

            return(true);
        }
コード例 #23
0
        /// <summary>
        /// This reads and sets its state or attributes stored in a <c>XML</c> format
        /// with the given reader.
        /// </summary>
        /// <param name="reader">
        /// The reader with which the <c>XML</c> attributes of this object are accessed.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If the <paramref name="reader"/> is <see langword="null"/>.
        /// </exception>
        public override void ReadXml(XmlReader reader)
        {
            BuildExceptions.NotNull(reader, "reader");

            Debug.Assert(reader.NodeType == XmlNodeType.Element);
            if (reader.NodeType != XmlNodeType.Element)
            {
                return;
            }
            if (!String.Equals(reader.Name, TagName,
                               StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            _itemId = reader.GetAttribute("id");
            string nodeText = reader.GetAttribute("type");

            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemType = MediaItemType.None;

                switch (nodeText.ToLower())
                {
                case "image":
                    _itemType = MediaItemType.Image;
                    break;

                case "video":
                    _itemType = MediaItemType.Video;
                    break;

                case "flash":
                    _itemType = MediaItemType.Flash;
                    break;

                case "silverlight":
                    _itemType = MediaItemType.Silverlight;
                    break;

                case "youtube":
                    _itemType = MediaItemType.YouTube;
                    break;

                case "pdf":
                    _itemType = MediaItemType.Pdf;
                    break;

                case "xps":
                    _itemType = MediaItemType.Xps;
                    break;
                }
            }
            nodeText = reader.GetAttribute("width");
            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemWidth = Convert.ToInt32(nodeText);
            }
            nodeText = reader.GetAttribute("height");
            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemHeight = Convert.ToInt32(nodeText);
            }
            nodeText = reader.GetAttribute("unit");
            if (!String.IsNullOrEmpty(nodeText))
            {
                _itemUnit = MediaSizeUnit.None;

                switch (nodeText.ToLower())
                {
                case "pixel":
                    _itemUnit = MediaSizeUnit.Pixel;
                    break;

                case "point":
                    _itemUnit = MediaSizeUnit.Point;
                    break;

                case "percent":
                    _itemUnit = MediaSizeUnit.Percent;
                    break;

                case "em":
                    _itemUnit = MediaSizeUnit.Em;
                    break;

                case "pica":
                    _itemUnit = MediaSizeUnit.Pica;
                    break;

                case "ex":
                    _itemUnit = MediaSizeUnit.Ex;
                    break;
                }
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            XmlNodeType nodeType = XmlNodeType.None;

            while (reader.Read())
            {
                nodeText = reader.Name;
                nodeType = reader.NodeType;

                if (nodeType == XmlNodeType.Element)
                {
                    if (String.Equals(reader.Name, "image",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        if (_itemType == MediaItemType.YouTube)
                        {
                            _itemName = reader.GetAttribute("file");
                        }
                        else
                        {
                            _itemPath = new BuildFilePath(reader.GetAttribute("file"));
                        }
                        _useMap  = reader.GetAttribute("usemap");
                        nodeText = reader.GetAttribute("resolveMapLinks");
                        if (!String.IsNullOrEmpty(nodeText))
                        {
                            _resolveLinks = Convert.ToBoolean(nodeText);
                        }
                    }
                    else if (String.Equals(reader.Name, "altText",
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        _altText = reader.ReadString();
                    }
                    else if (String.Equals(reader.Name, "map",
                                           StringComparison.OrdinalIgnoreCase))
                    {
                        _imageMap = new MediaImageMap();
                        _imageMap.ReadXml(reader);
                    }
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (String.Equals(reader.Name, "item",
                                      StringComparison.OrdinalIgnoreCase))
                    {
                        break;
                    }
                }
            }
        }
コード例 #24
0
        private static async Task <bool> PrepareFiles(object mediaItem, MediaItemType type)
        {
            if (type == MediaItemType.Song)
            {
                if (mediaItem.GetType() == typeof(Song))
                {
                    Song        song = mediaItem as Song;
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song.SongURI);

                    if (file == null)
                    {
                        filesToShare = null;
                        return(false);
                    }

                    filesToShare.Add(file);
                }
                else
                {
                    // É LISTA DE STRING!!
                    List <string> list = mediaItem as List <string>;

                    foreach (string path in list)
                    {
                        StorageFile file = await StorageFile.GetFileFromPathAsync(path);

                        if (file != null)
                        {
                            filesToShare.Add(file);
                        }
                    }
                }
            }
            else if (type == MediaItemType.Album)
            {
                Album album = mediaItem as Album;

                var songs = Ctr_Song.Current.GetSongsByAlbum(album);
                foreach (Song song in songs)
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song.SongURI);

                    if (file != null)
                    {
                        filesToShare.Add(file);
                    }
                }
            }
            else if (type == MediaItemType.Artist)
            {
                Artist artist = mediaItem as Artist;

                var songs = Ctr_Song.Current.GetSongsByArtist(artist);
                foreach (Song song in songs)
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song.SongURI);

                    if (file != null)
                    {
                        filesToShare.Add(file);
                    }
                }
            }
            else if (type == MediaItemType.Folder)
            {
                FolderItem item = mediaItem as FolderItem;
                if (item.IsFolder)
                {
                    StorageFolder subFolder = await StorageFolder.GetFolderFromPathAsync(item.Path);

                    var subFolderItems = await StorageHelper.ReadFolder(subFolder);

                    foreach (StorageFile f in subFolderItems)
                    {
                        if (StorageHelper.IsMusicFile(f.Path))
                        {
                            filesToShare.Add(f);
                        }
                    }
                }
            }
            else if (type == MediaItemType.Playlist)
            {
                Playlist playlist = mediaItem as Playlist;

                foreach (string song in playlist.Songs)
                {
                    StorageFile file = await StorageFile.GetFileFromPathAsync(song);

                    if (file != null)
                    {
                        filesToShare.Add(file);
                    }
                }
            }

            if (filesToShare.Count == 0)
            {
                return(false);
            }

            DataTransferManager.ShowShareUI();

            return(true);
        }
コード例 #25
0
        public static async void ShowPopupMenu(this FrameworkElement fwe, object mediaItem, object sender, Point point, MediaItemType type)
        {
            page = fwe;

            MenuFlyout menu = new MenuFlyout()
            {
                MenuFlyoutPresenterStyle = Application.Current.Resources["MenuFlyoutModernStyle"] as Style,
            };

            // SE O MENU FOR DO TIPO SONG
            if (type == MediaItemType.Song)
            {
                Song song = Ctr_Song.Current.GetSong(mediaItem as Song);

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(songs));
                };

                menu.Items.Add(item1);

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(songs);
                    }
                };

                menu.Items.Add(item3);


                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs, true));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(song, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);

                MenuFlyoutItem item6 = new MenuFlyoutItem()
                {
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };

                if (song.IsFavorite)
                {
                    item6.Text = ApplicationInfo.Current.Resources.GetString("RemoveFromFavoritesString");
                    item6.Tag  = "";
                }
                else
                {
                    item6.Text = ApplicationInfo.Current.Resources.GetString("AddToFavoritesString");
                    item6.Tag  = "";
                }

                item6.Click += (s, a) =>
                {
                    //remove favorite mark
                    if (song.IsFavorite)
                    {
                        Ctr_Song.Current.SetFavoriteState(song, false);
                    }
                    //add favorite mark
                    else
                    {
                        Ctr_Song.Current.SetFavoriteState(song, true);
                    }
                };

                menu.Items.Add(item6);

                MenuFlyoutItem item7 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("GoToArtistString"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item7.Click += (s, a) =>
                {
                    Artist artist = new Artist();
                    artist.Name = song.Artist;

                    PageHelper.MainPage?.Navigate(typeof(ArtistPage), artist);
                };

                menu.Items.Add(item7);

                MenuFlyoutItem item8 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("GoToAlbumString"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item8.Click += (s, a) =>
                {
                    Album album = new Album()
                    {
                        Name     = song.Album,
                        Artist   = song.Artist,
                        AlbumID  = song.AlbumID,
                        Year     = Convert.ToInt32(song.Year),
                        Genre    = song.Genre,
                        HexColor = song.HexColor
                    };

                    PageHelper.MainPage?.Navigate(typeof(AlbumPage), album);
                };

                menu.Items.Add(item8);

                //MenuFlyoutItem item6 = new MenuFlyoutItem()
                //{
                //    Text = "Editar",
                //    Tag = "",
                //    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                //};
                //item6.Click += (s, a) =>
                //{
                //    PageHelper.MainPage.PageFrame.Navigate(typeof(TagEditor), song);
                //};

                //menu.Items.Add(item6);
            }
            // SE O MENU FOR DO TIPO ALBUM
            else if (type == MediaItemType.Album)
            {
                Album         album = mediaItem as Album;
                List <Song>   songs = Ctr_Song.Current.GetSongsByAlbum(album);
                List <string> list  = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(album, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);

                MenuFlyoutItem item6 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("GoToArtistString"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item6.Click += (s, a) =>
                {
                    Artist artist = new Artist();
                    artist.Name = album.Artist;

                    PageHelper.MainPage?.Navigate(typeof(ArtistPage), artist);
                };

                menu.Items.Add(item6);
            }
            // SE O MENU FOR DO TIPO ARTIST
            else if (type == MediaItemType.Artist)
            {
                Artist        artist = mediaItem as Artist;
                List <Song>   songs  = Ctr_Song.Current.GetSongsByArtist(artist);
                List <string> list   = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(artist, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            //SE O MENU FOR DO TIPO FOLDER
            else if (type == MediaItemType.Folder)
            {
                List <string> list = new List <string>();

                FolderItem item = mediaItem as FolderItem;

                StorageFolder subFolder = await StorageFolder.GetFolderFromPathAsync(item.Path);

                var subFolderItems = await StorageHelper.ReadFolder(subFolder);

                foreach (StorageFile f in subFolderItems)
                {
                    if (StorageHelper.IsMusicFile(f.Path))
                    {
                        list.Add(f.Path);
                    }
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(item, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            // SE O MENU FOR DO TIPO PLAYLIST
            else if (type == MediaItemType.Playlist)
            {
                Playlist playlist = mediaItem as Playlist;

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(playlist.Songs));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item2);


                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs, true));

                    //if (PageHelper.NowPlaying != null)
                    //{
                    //    PageHelper.NowPlaying.ClearPlaylist();

                    //    MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                    //    await Task.Delay(200);
                    //    PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    //}
                };

                menu.Items.Add(item3);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    if (await page.ShareMediaItem(playlist, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Delete"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessage"), ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessageTitle"));
                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("Yes"), async(t) =>
                    {
                        StorageFolder playlistsFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Playlists", CreationCollisionOption.OpenIfExists);

                        IStorageItem playlistItem = await playlistsFolder.TryGetItemAsync(playlist.PlaylistFileName);

                        if (playlistItem != null)
                        {
                            try
                            {
                                await playlistItem.DeleteAsync(StorageDeleteOption.PermanentDelete);

                                if (PageHelper.PlaylistPage != null)
                                {
                                    if (PageHelper.MainPage != null)
                                    {
                                        PageHelper.MainPage.GoBack();
                                    }
                                }
                                else if (PageHelper.Playlists != null)
                                {
                                    PageHelper.Playlists.LoadPlaylists();
                                }
                            }
                            catch
                            {
                            }
                        }
                    }));

                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("No")));

                    md.CancelCommandIndex  = 1;
                    md.DefaultCommandIndex = 1;

                    await md.ShowAsync();
                };

                menu.Items.Add(item5);
            }

            try
            {
                menu.ShowAt(sender as FrameworkElement, point);
            }
            catch
            {
                menu.ShowAt(sender as FrameworkElement);
            }
        }
コード例 #26
0
 public IMediaItem CreateSymbolicLink(string name, MediaItemType type)
 {
     return(null);
 }
コード例 #27
0
        public static void ShowPopupMenu(this Page page, object mediaItem, object sender, Point point, MediaItemType type)
        {
            currentPage = page;
            MenuFlyout menu = new MenuFlyout()
            {
                MenuFlyoutPresenterStyle = Application.Current.Resources["MenuFlyoutModernStyle"] as Style,
            };

            // SE O MENU FOR DO TIPO SONG
            if (type == MediaItemType.Song)
            {
                Song song = mediaItem as Song;

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(songs));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(songs);
                    }
                };

                menu.Items.Add(item3);


                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    List <string> songs = new List <string>();
                    songs.Add(song.SongURI);

                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(songs, true));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(song, type) == false)
                    {
                        MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("ShareErrorMessage"));
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);

                //MenuFlyoutItem item6 = new MenuFlyoutItem()
                //{
                //    Text = "Editar",
                //    Tag = "",
                //    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                //};
                //item6.Click += (s, a) =>
                //{
                //    PageHelper.MainPage.PageFrame.Navigate(typeof(TagEditor), song);
                //};

                //menu.Items.Add(item6);
            }
            // SE O MENU FOR DO TIPO ALBUM
            else if (type == MediaItemType.Album)
            {
                Album         album = mediaItem as Album;
                List <Song>   songs = CollectionHelper.GetSongsByAlbumID(album.AlbumID);
                List <string> list  = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(album, type) == false)
                    {
                        MessageDialog md = new MessageDialog("Não foi possível compartilhar este item");
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            // SE O MENU FOR DO TIPO ARTIST
            else if (type == MediaItemType.Artist)
            {
                Artist        artist = mediaItem as Artist;
                List <Song>   songs  = CollectionHelper.GetSongsByArtist(artist.Name);
                List <string> list   = new List <string>();
                foreach (Song s in songs)
                {
                    list.Add(s.SongURI);
                }

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(list));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list));
                };

                menu.Items.Add(item2);

                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylistFile"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += (s, a) =>
                {
                    if (PageHelper.MainPage != null)
                    {
                        PageHelper.MainPage.CreateAddToPlaylistPopup(list);
                    }
                };

                menu.Items.Add(item3);

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(list, true));
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(artist, type) == false)
                    {
                        MessageDialog md = new MessageDialog("Não foi possível compartilhar este item");
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item5);
            }
            // SE O MENU FOR DO TIPO PLAYLIST
            else if (type == MediaItemType.Playlist)
            {
                Playlist playlist = mediaItem as Playlist;

                MenuFlyoutItem item1 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Play"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item1.Click += (s, a) =>
                {
                    MessageService.SendMessageToBackground(new SetPlaylistMessage(playlist.Songs));
                };

                menu.Items.Add(item1);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item2 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("AddToPlaylist"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item2.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item2);


                MenuFlyoutItem item3 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("PlayNext"),
                    Tag   = "\uEA52",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item3.Click += async(s, a) =>
                {
                    MessageService.SendMessageToBackground(new AddSongsToPlaylist(playlist.Songs, true));

                    if (PageHelper.NowPlaying != null)
                    {
                        PageHelper.NowPlaying.ClearPlaylist();

                        MessageService.SendMessageToBackground(new ActionMessage(BackgroundAudioShared.Messages.Action.AskPlaylist));
                        await Task.Delay(200);

                        PageHelper.NowPlaying.UpdatePlayerInfo(CustomPlaylistsHelper.CurrentTrackPath);
                    }
                };

                menu.Items.Add(item3);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item4 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Share"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item4.Click += async(s, a) =>
                {
                    if (await currentPage.ShareMediaItem(playlist, type) == false)
                    {
                        MessageDialog md = new MessageDialog("Não foi possível compartilhar este item");
                        await md.ShowAsync();
                    }
                };

                menu.Items.Add(item4);

                menu.Items.Add(new MenuFlyoutSeparator());

                MenuFlyoutItem item5 = new MenuFlyoutItem()
                {
                    Text  = ApplicationInfo.Current.Resources.GetString("Delete"),
                    Tag   = "",
                    Style = Application.Current.Resources["ModernMenuFlyoutItem"] as Style,
                };
                item5.Click += async(s, a) =>
                {
                    MessageDialog md = new MessageDialog(ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessage"), ApplicationInfo.Current.Resources.GetString("DeletePlaylistMessageTitle"));
                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("Yes"), async(t) =>
                    {
                        StorageFolder playlistsFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Playlists", CreationCollisionOption.OpenIfExists);

                        IStorageItem playlistItem = await playlistsFolder.TryGetItemAsync(playlist.PlaylistFileName);

                        if (playlistItem != null)
                        {
                            try
                            {
                                await playlistItem.DeleteAsync(StorageDeleteOption.PermanentDelete);

                                if (PageHelper.PlaylistPage != null)
                                {
                                    if (PageHelper.MainPage != null)
                                    {
                                        PageHelper.MainPage.GoBack();
                                    }
                                }
                                else if (PageHelper.Playlists != null)
                                {
                                    PageHelper.Playlists.LoadPlaylists();
                                }
                            }
                            catch
                            {
                            }
                        }
                    }));

                    md.Commands.Add(new UICommand(ApplicationInfo.Current.Resources.GetString("No")));

                    md.CancelCommandIndex  = 1;
                    md.DefaultCommandIndex = 1;

                    await md.ShowAsync();
                };

                menu.Items.Add(item5);
            }

            try
            {
                menu.ShowAt(sender as FrameworkElement, point);
            }
            catch
            {
                menu.ShowAt(sender as FrameworkElement);
            }
        }
コード例 #28
0
ファイル: MediaFolder.cs プロジェクト: BradFuller/pspplayer
 public IMediaItem CreateSymbolicLink( string name, MediaItemType type )
 {
     return null;
 }
コード例 #29
0
ファイル: MainForm.cs プロジェクト: hmehr/OSS
        /// <summary>
        /// Gets the color of the sub node.
        /// </summary>
        /// <param name="mediaItemTye">The media item tye.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2007-08-09</remarks>
        private Color GetSubNodeColor(MediaItemType mediaItemTye)
        {
            switch (mediaItemTye)
            {
                case MediaItemType.Answer:
                    if (dictionaryManager.GetWord(settings.ActualCard, MLifter.DAL.Interfaces.Side.Answer) == "")
                        return STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                    return dictionaryManager.HasMediaFile(settings.ActualCard, false, MLifter.DAL.Interfaces.Side.Answer) ? STANDARD_APPEARANCE.COLOR_CARD_COMPLETE : STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                case MediaItemType.AnswerExample:
                    if (dictionaryManager.GetSentence(settings.ActualCard, MLifter.DAL.Interfaces.Side.Answer) == "")
                        return STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                    return dictionaryManager.HasMediaFile(settings.ActualCard, true, MLifter.DAL.Interfaces.Side.Answer) ? STANDARD_APPEARANCE.COLOR_CARD_COMPLETE : STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                case MediaItemType.Question:
                    if (dictionaryManager.GetWord(settings.ActualCard, MLifter.DAL.Interfaces.Side.Question) == "")
                        return STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                    return dictionaryManager.HasMediaFile(settings.ActualCard, false, MLifter.DAL.Interfaces.Side.Question) ? STANDARD_APPEARANCE.COLOR_CARD_COMPLETE : STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                case MediaItemType.QuestionExample:
                    if (dictionaryManager.GetSentence(settings.ActualCard, MLifter.DAL.Interfaces.Side.Question) == "")
                        return STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
                    return dictionaryManager.HasMediaFile(settings.ActualCard, true, MLifter.DAL.Interfaces.Side.Question) ? STANDARD_APPEARANCE.COLOR_CARD_COMPLETE : STANDARD_APPEARANCE.COLOR_CARD_NOTHING;
            }

            return Color.White;
        }
コード例 #30
0
ファイル: MainForm.cs プロジェクト: hmehr/OSS
        /// <summary>
        /// Gets the tree node.
        /// </summary>
        /// <param name="mediaItemType">Type of the media item.</param>
        /// <returns></returns>
        /// <remarks>Documented by Dev05, 2007-08-09</remarks>
        private TreeNode GetTreeNode(MediaItemType mediaItemType)
        {
            TreeNode node = null;

            switch (mediaItemType)
            {
                case MediaItemType.Answer:
                    node = new TreeNode(Resources.LISTBOXFIELDS_ANSWER_TEXT.Remove(Resources.LISTBOXFIELDS_ANSWER_TEXT.LastIndexOf(' ')));
                    node.Checked = settings.RecordAnswer;
                    node.Tag = dictionaryManager.GetWord(settings.ActualCard, MLifter.DAL.Interfaces.Side.Answer);
                    break;
                case MediaItemType.AnswerExample:
                    node = new TreeNode(Resources.LISTBOXFIELDS_EXANSWER_TEXT.Remove(Resources.LISTBOXFIELDS_EXANSWER_TEXT.LastIndexOf(' ')));
                    node.Checked = settings.RecordAnswerExample;
                    node.Tag = dictionaryManager.GetSentence(settings.ActualCard, MLifter.DAL.Interfaces.Side.Answer);
                    break;
                case MediaItemType.Question:
                    node = new TreeNode(Resources.LISTBOXFIELDS_QUESTION_TEXT.Remove(Resources.LISTBOXFIELDS_QUESTION_TEXT.LastIndexOf(' ')));
                    node.Checked = settings.RecordQuestion;
                    node.Tag = dictionaryManager.GetWord(settings.ActualCard, MLifter.DAL.Interfaces.Side.Question);
                    break;
                case MediaItemType.QuestionExample:
                    node = new TreeNode(Resources.LISTBOXFIELDS_EXQUESTION_TEXT.Remove(Resources.LISTBOXFIELDS_EXQUESTION_TEXT.LastIndexOf(' ')));
                    node.Checked = settings.RecordQuestionExample;
                    node.Tag = dictionaryManager.GetSentence(settings.ActualCard, MLifter.DAL.Interfaces.Side.Question);
                    break;
            }

            if (node.Tag is string && (node.Tag as string) == "")
            {
                node.Text += Resources.NO_TEXT_MESSAGE;
                node.Checked = false;
            }

            node.BackColor = GetSubNodeColor(mediaItemType);
            return node;
        }
コード例 #31
0
ファイル: MainForm.cs プロジェクト: hmehr/OSS
        /// <summary>
        /// Determines whether the media type is selected.
        /// </summary>
        /// <param name="mediaItemType">Type of the media item.</param>
        /// <returns>
        /// 	<c>true</c> if the media type is selected; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>Documented by Dev05, 2007-08-22</remarks>
        private bool IsMediaTypeSelected(MediaItemType mediaItemType)
        {
            switch (mediaItemType)
            {
                case MediaItemType.Answer:
                    return settings.RecordAnswer;
                case MediaItemType.AnswerExample:
                    return settings.RecordAnswerExample;
                case MediaItemType.Question:
                    return settings.RecordQuestion;
                case MediaItemType.QuestionExample:
                    return settings.RecordQuestionExample;
            }

            return false;
        }
コード例 #32
0
ファイル: MediaFolder.cs プロジェクト: BradFuller/pspplayer
        public IMediaItem CreateSymbolicLink( string name, MediaItemType type )
        {
            if( _device.IsReadOnly == true )
                return null;

            // TODO: Support creation of symbolic links (may be hard on native fs)
            throw new NotImplementedException();
        }