MixRadio Developers - MixRadio .Net SDK Example Bands Around

MixRadio Example: “Bands Around”

Bands Around is an example application demonstrating the use of MixRadio API together with the Windows Phone 8 Map control in a location aware manner. After calculating the device’s current location, the app will show bands and artists originating from the vicinity of that spot. The pushpins, representing the bands and artists, are updated on the fly as user moves around the world by flicking and dragging the map. More information on artists is made available in MixRadio application, which is launched when a pushpin is tapped.

Building the application

Clone the application solution source code and open the BandsAround.sln file in the Visual Studio. Start building and running the application by hitting F5 or selecting Start Debugging from the Debug menu.

Design

Bands Around is a lean Windows Phone 8 example application demonstrating the basics of the MixRadio API as well as integration with other Windows Phone features such as locationing and maps. When application is launched, a map centered on device’s current position fills the screen. Map is then populated with bands originating around that geographic spot, shown on the map as pushpins.


Pushpins representing the bands are updated on the fly as user drags and flicks the map to make a musical journey through the world. Tapping on a pushpin launches MixRadio to show the artist details view with a possibility to download tracks and albums from the selected artist.


Searching artists and bands nearby location

The API offers a handy method for requesting bands and artists originating nearby a specified location. The code block below shows all there is to do in order to receive a list of artists originating from device’s current position:

namespace BandsAround { 

    ...

    public partial class MainPage : PhoneApplicationPage
    {
        // MixRadio API with which to request nearby artists
        MusicClient client = null;

        // A collection of artists represented on the map with Pushpins.
        private ObservableCollection<Artist> nearbyArtists = null;

        ...

        public MainPage()
        {
            this.Loaded += MainPage_Loaded;
            ...
        }  

        private async void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            ...

            if (geoLocator == null)
            {
                geoLocator = new Geolocator();
                Geoposition pos = await geoLocator.GetGeopositionAsync();
 
                if (pos != null && pos.Coordinate != null)
                {
                    Map.Center = new GeoCoordinate(pos.Coordinate.Latitude, pos.Coordinate.Longitude);
                    Map.ZoomLevel = 10;
                    GetNearbyArtists();
                }
            }
        }


        private async void GetNearbyArtists()
        {
            ...

            if (client == null)
            {
                client = new MusicClient(MY_CLIENT_ID);
            }

            var res = await client.GetArtistsAroundLocationAsync(Map.Center.Latitude, Map.Center.Longitude, 50, 0, 40);
            if (res.Result != null)
            {
                if (nearbyArtists == null)
                {
                    nearbyArtists = new ObservableCollection<Artist>();
                    this.MapItems.ItemsSource = nearbyArtists;
                }

                for (int i = 0; i < res.Result.Count; i++)
                {
                    ...

                    nearbyArtists.Add(res.Result[i]);

                    ...
                }
            }

            ... 
        } 
    }
}  

Downloads

This example application is hosted in GitHub, where you can check the latest activities, report issues, browse source, ask questions or even contribute to the project yourself.

Contribute to this article

Want to edit or suggest changes to this content? You can edit and submit changes to this article using GitHub.