Exemple #1
0
        public void TestProperties()
        {
            Mix mix = new Mix() { Id = TestId, Name = TestName, ParentalAdvisory = true, Thumb100Uri = new Uri("http://assets.ent.nokia.com/p/d/music_image/100x100/1182.jpg"), Thumb200Uri = new Uri("http://assets.ent.nokia.com/p/d/music_image/200x200/1182.jpg") };

            Assert.AreEqual(TestId, mix.Id, "Expected the property to persist");
            Assert.AreEqual(TestName, mix.Name, "Expected the property to persist");
        }
Exemple #2
0
        public void TestLinkingProperties()
        {
            var item = new Mix() { Id = TestId };
            var itemWithNullId = new Mix();

            Assert.IsNotNull(item.AppToAppUri, "Expected App to App URI to be calculated");
            Assert.IsNull(itemWithNullId.AppToAppUri, "Expected App to App URI not to be calculated");

            Assert.IsNotNull(item.WebUri, "Expected Web URI to be calculated");
            Assert.IsNull(itemWithNullId.WebUri, "Expected Web URI not to be calculated");
        }
Exemple #3
0
        public void TestJsonParsing()
        {
            Assert.IsNull(Mix.FromJToken(null, null), "Expected a null return");

            Mix mix = new Mix() { Id = "1234", Name = "Metal", ParentalAdvisory = true };
            JObject json = JObject.Parse("{\"id\":\"1234\",\"name\":\"Metal\",\"parentaladvisory\":true, \"thumbnails\": { \"100x100\": \"http://download.ch1.vcdn.nokia.com/p/d/music_image/100x100/1182.jpg\", \"200x200\": \"http://download.ch1.vcdn.nokia.com/p/d/music_image/200x200/1182.jpg\" } }");

            Mix fromJson = Mix.FromJToken(json, null) as Mix;

            Assert.IsNotNull(fromJson, "Expected a Mix object");

            Assert.IsTrue(mix.Equals(fromJson), "Expected the same Mix");
        }
Exemple #4
0
        /// <summary>
        /// Launches MixRadio to start playback of the mix using the PlayMixTask
        /// </summary>
        /// <param name="mix">The mix.</param>
        /// <returns>An async task to await</returns>
        public static async Task Play(this Mix mix)
        {
            if (!string.IsNullOrEmpty(mix.Id))
            {
                PlayMixTask task = new PlayMixTask()
                {
                    MixId = mix.Id
                };
                await task.Show().ConfigureAwait(false);

                return;
            }
#if WINDOWS_PHONE
            else if (mix.Seeds.Where(s => s.Type == SeedType.UserId).Count() > 0)
            {
                await new PlayMeTask().Show().ConfigureAwait(false);
                return;
            }
#endif

            if (mix.Seeds != null)
            {
                var artistSeeds = mix.Seeds.Where(s => (s.Type == SeedType.ArtistId || s.Type == SeedType.ArtistName));

                // for now, just take the first artist name - need to support multiple soon though
                var name = artistSeeds.Select(s => s.Name).Where(s => !string.IsNullOrEmpty(s)).FirstOrDefault();
                if (!string.IsNullOrEmpty(name))
                {
                    await new PlayMixTask()
                    {
                        ArtistName = name
                    }.Show().ConfigureAwait(false);
                    return;
                }
            }

            throw new InvalidOperationException();
        }
Exemple #5
0
        /// <summary>
        /// Creates a Mix from a JSON Object
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="settings">The settings.</param>
        /// <returns>
        /// A Mix object
        /// </returns>
        internal static Mix FromJToken(JToken item, IMusicClientSettings settings)
        {
            const string PlayMeThumbUri = "http://dev.mixrad.io/assets/playme/{0}x{0}.png";

            if (item == null)
            {
                return(null);
            }

            bool   parentalAdvisory      = false;
            JToken parentaladvisoryToken = item["parentaladvisory"];

            if (parentaladvisoryToken != null)
            {
                parentalAdvisory = item.Value <bool>("parentaladvisory");
            }

            JToken featuredArtists     = item["featuredartists"];
            var    featuredArtistsList = new List <Artist>();

            if (featuredArtists != null)
            {
                foreach (JToken token in featuredArtists)
                {
                    Artist artist = Artist.FromJToken(token, settings);
                    featuredArtistsList.Add(artist);
                }
            }

            Uri square50  = null;
            Uri square100 = null;
            Uri square200 = null;
            Uri square320 = null;
            Uri square640 = null;

            var thumbnailsToken = item["thumbnails"];

            MusicItem.ExtractThumbs(thumbnailsToken, out square50, out square100, out square200, out square320);

            if (thumbnailsToken != null)
            {
                square640 = Mix.ExtractThumb(thumbnailsToken, "640x640");
            }

            var            seeds          = item["seeds"];
            SeedCollection seedCollection = null;

            if (seeds != null)
            {
                seedCollection = SeedCollection.FromJson(item.ToString());
            }
            else
            {
                var mixId = item.Value <string>("id");

                if (!string.IsNullOrEmpty(mixId))
                {
                    seedCollection = new SeedCollection(Seed.FromMixId(mixId));
                }
            }

            var name = item.Value <string>("name");

            var description = item.Value <string>("description");

            if (seedCollection != null && seedCollection.Count > 0)
            {
                if (seedCollection.Count(s => s.Type == SeedType.UserId) > 0)
                {
                    if (square50 == null)
                    {
                        square50 = new Uri(string.Format(PlayMeThumbUri, 50));
                    }

                    if (square100 == null)
                    {
                        square100 = new Uri(string.Format(PlayMeThumbUri, 100));
                    }

                    if (square200 == null)
                    {
                        square200 = new Uri(string.Format(PlayMeThumbUri, 200));
                    }

                    if (square320 == null)
                    {
                        square320 = new Uri(string.Format(PlayMeThumbUri, 320));
                    }

                    if (square640 == null)
                    {
                        square640 = new Uri(string.Format(PlayMeThumbUri, 640));
                    }

                    if (string.IsNullOrEmpty(name))
                    {
                        name = "Play Me";
                    }
                }
                else if (seedCollection.Count(s => s.Type == SeedType.ArtistId) > 0)
                {
                    var artistSeeds = seedCollection.Where(s => (s.Type == SeedType.ArtistId)).ToArray();

                    if (string.IsNullOrEmpty(name))
                    {
                        // Derive a name
                        var names = artistSeeds.Select(s => s.Name).Where(s => !string.IsNullOrEmpty(s)).ToArray();

                        name = names.Length > 0
                                ? string.Join(", ", names)
                                : "Artist Mix";
                    }

                    // Derive a thumbnail image
                    var idSeed = artistSeeds.FirstOrDefault(s => !string.IsNullOrEmpty(s.Id));
                    if (idSeed != null && settings != null)
                    {
                        var builder = new ArtistImageUriWriter(settings);

                        if (square50 == null)
                        {
                            square50 = builder.BuildForId(idSeed.Id, 50);
                        }

                        if (square100 == null)
                        {
                            square100 = builder.BuildForId(idSeed.Id, 100);
                        }

                        if (square200 == null)
                        {
                            square200 = builder.BuildForId(idSeed.Id, 200);
                        }

                        if (square320 == null)
                        {
                            square320 = builder.BuildForId(idSeed.Id, 320);
                        }

                        if (square640 == null)
                        {
                            square640 = builder.BuildForId(idSeed.Id, 640);
                        }
                    }
                }
            }

            return(new Mix()
            {
                Name = name,
                TrackCount = item.Value <int>("numbertracks"),
                ParentalAdvisory = parentalAdvisory,
                Seeds = seedCollection,
                Thumb50Uri = square50,
                Thumb100Uri = square100,
                Thumb200Uri = square200,
                Thumb320Uri = square320,
                Thumb640Uri = square640,
                Description = description,
                FeaturedArtists = featuredArtistsList
            });
        }
Exemple #6
0
 /// <summary>
 /// Plays the Mix in MixRadio
 /// </summary>
 /// <returns>An async task to await</returns>
 public async Task Show()
 {
     if (!string.IsNullOrEmpty(this.MixId))
     {
         var mix = new Mix { Id = this.MixId };
         await this.Launch(mix.AppToAppUri, mix.WebUri).ConfigureAwait(false);
     }
     else if (!string.IsNullOrEmpty(this._artistId))
     {
         var artist = new Artist { Id = this._artistId };
         await this.Launch(artist.AppToAppPlayUri, artist.WebUri).ConfigureAwait(false);
     }
     else if (!string.IsNullOrEmpty(this._artistName))
     {
         var artist = new Artist { Name = this._artistName };
         await this.Launch(artist.AppToAppPlayUri, artist.WebUri).ConfigureAwait(false);
     }
     else
     {
         throw new InvalidOperationException("Please set a mix ID, artist id or artist name before calling Show()");
     }
 }
Exemple #7
0
 public void HashCodeCanBeRetrievedWhenIdIsNull()
 {
     Mix mix = new Mix();
     Assert.IsNotNull(mix.GetHashCode(), "Expected a hash code");
 }
Exemple #8
0
 public void TestOverrides()
 {
     Mix mix = new Mix() { Id = TestId, Name = TestName };
     Assert.IsNotNull(mix.GetHashCode(), "Expected a hash code");
     Assert.IsFalse(mix.Equals(TestId), "Expected inequality");
 }