Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
            public void CreatesEmptyTemporaryFile()
            {
                var fileSystem = new MockFileSystem();
                var metadata = new NetworkSong();

                var song = MobileSong.Create(metadata, Observable.Never<byte[]>(), fileSystem);

                Assert.Equal(0, fileSystem.FileInfo.FromFileName(song.PlaybackPath).Length);
            }
Ejemplo n.º 3
0
            public void StoresDataUponArrival()
            {
                var fileSystem = new MockFileSystem();
                var metadata = new NetworkSong();
                var data = new byte[] { 0, 1 };

                var song = MobileSong.Create(metadata, Observable.Return(data), fileSystem);

                Assert.Equal(data, fileSystem.File.ReadAllBytes(song.PlaybackPath));
            }
Ejemplo n.º 4
0
            public void SetsTemporaryFileAsSongPath()
            {
                var fileSystem = new MockFileSystem();
                var metadata = new NetworkSong();

                var song = MobileSong.Create(metadata, Observable.Never<byte[]>(), fileSystem);

                DirectoryInfoBase tempDir = fileSystem.DirectoryInfo.FromDirectoryName(fileSystem.Path.GetTempPath());

                Assert.Equal(song.OriginalPath, tempDir.GetFiles().First().FullName);
                Assert.Equal(song.PlaybackPath, tempDir.GetFiles().First().FullName);
            }
Ejemplo n.º 5
0
            private void WaitsForSongData()
            {
                var metadata = new NetworkSong();
                var data = new Subject<byte[]>();
                var song = MobileSong.Create(metadata, data, new MockFileSystem());

                Task awaiter = song.PrepareAsync(YoutubeStreamingQuality.Low);

                Assert.False(awaiter.IsCompleted);

                data.OnNext(new byte[] { 0, 1 });
                data.OnCompleted();

                Assert.True(awaiter.IsCompleted);
            }