예제 #1
0
        internal static MobileSong Create(NetworkSong metaData, IObservable<byte[]> data, IFileSystem fileSystem = null)
        {
            fileSystem = fileSystem ?? new FileSystem();

            string tempPath = fileSystem.Path.GetTempFileName();

            // Lol, MediaElement is too stupid to play a file with a .tmp extension
            string newName = Path.ChangeExtension(tempPath, ".mp3");
            fileSystem.File.Move(tempPath, newName);
            tempPath = newName;

            var song = new MobileSong(tempPath, metaData.Duration)
            {
                Album = metaData.Album,
                Artist = metaData.Artist,
                Genre = metaData.Genre,
                Title = metaData.Title
            };

            var conn = data.FirstAsync()
                .Do(x => fileSystem.File.WriteAllBytes(tempPath, x))
                .ToUnit()
                .Multicast(song.dataGate);
            conn.Connect();

            return song;
        }
예제 #2
0
        internal static MobileSong Create(NetworkSong metaData, IObservable <byte[]> data, IFileSystem fileSystem = null)
        {
            fileSystem = fileSystem ?? new FileSystem();

            string tempPath = fileSystem.Path.GetTempFileName();

            // Lol, MediaElement is too stupid to play a file with a .tmp extension
            string newName = Path.ChangeExtension(tempPath, ".mp3");

            fileSystem.File.Move(tempPath, newName);
            tempPath = newName;

            var song = new MobileSong(tempPath, metaData.Duration)
            {
                Album  = metaData.Album,
                Artist = metaData.Artist,
                Genre  = metaData.Genre,
                Title  = metaData.Title
            };

            var conn = data.FirstAsync()
                       .Do(x => fileSystem.File.WriteAllBytes(tempPath, x))
                       .ToUnit()
                       .Multicast(song.dataGate);

            conn.Connect();

            return(song);
        }
예제 #3
0
        private async Task <ResponseInfo> QueueRemoteSong(JToken parameters)
        {
            AccessPermission permission = await this.library.RemoteAccessControl.ObserveAccessPermission(this.accessToken).FirstAsync();

            if (permission == AccessPermission.Guest)
            {
                int?remainingVotes = await this.library.RemoteAccessControl.ObserveRemainingVotes(this.accessToken).FirstAsync();

                if (remainingVotes == null)
                {
                    return(CreateResponse(ResponseStatus.NotSupported, "Voting isn't supported"));
                }

                if (remainingVotes == 0)
                {
                    return(CreateResponse(ResponseStatus.Rejected, "Not enough votes left"));
                }
            }

            var transferInfo = parameters.ToObject <SongTransferInfo>();

            IObservable <byte[]> data = this.songTransfers.FirstAsync(x => x.TransferId == transferInfo.TransferId).Select(x => x.Data);

            var song = MobileSong.Create(transferInfo.Metadata, data);

            if (permission == AccessPermission.Guest)
            {
                this.library.AddGuestSongToPlaylist(song, this.accessToken);
            }

            else
            {
                this.library.AddSongsToPlaylist(new[] { song }, this.accessToken);
            }

            return(CreateResponse(ResponseStatus.Success));
        }