コード例 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            gmb = new Gmusicbrowser("macdesktop.orospakr.ca", 8081);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            playButton = FindViewById<ImageButton>
                (Resource.Id.PlayButton);
            titleTextView = FindViewById <TextView> (Resource.Id.TitleTextView);
            artistTextView = FindViewById <TextView> (Resource.Id.ArtistTextView);
            ratingBar = FindViewById <RatingBar> (Resource.Id.RatingBar);
            nextButton = FindViewById <ImageButton> (Resource.Id.NextButton);
            prevButton = FindViewById <ImageButton> (Resource.Id.PrevButton);
            volumeSeekBar = FindViewById <SeekBar> (Resource.Id.VolumeSeekBar);
            songSeekBar = FindViewById <SeekBar> (Resource.Id.SongSeekbar);

            playButton.Click += (sender, args) => {
                // button.Text = string.Format ("{0} clicks!", count++);
                gmb.PushNewPlayerState(new Player() { Playing = currentState.Playing == 1 ? 0 : 1 }).ContinueWith((playerResult) => {
                    if(playerResult.IsFaulted) {
                    } else {
                        HandleUpdatedStateFromNetwork(playerResult.Result);
                    }
                });
            };

            ratingBar.RatingBarChange += (sender, e) => {
                if(currentState != null && currentState.Current != null) {
                    var newSong = new Song() { Id = currentState.Current.Id, Rating = (int)(ratingBar.Rating * 20)};
                    gmb.PostUpdatedSong(newSong);
                }
            };

            nextButton.Click += (sender, e) => {
                gmb.Next().ContinueWith((playerResult) => {
                    HandleUpdatedStateFromNetwork(playerResult.Result);
                });
            };

            prevButton.Click += (sender, e) => {
                gmb.Previous ().ContinueWith((playerResult) => {
                    HandleUpdatedStateFromNetwork(playerResult.Result);
                });
            };

            volumeSeekBar.ProgressChanged += (sender, e) => {
                if(!preventSeekBarUpdates) {
                    gmb.PushNewPlayerState (new Player() { Volume = volumeSeekBar.Progress / (float)100 });
                }
            };

            songSeekBar.ProgressChanged += (sender, e) => {
                if(!preventSeekBarUpdates) {
                    gmb.PushNewPlayerState (new Player() { PlayPosition = songSeekBar.Progress });
                }
            };

            prog = new ProgressDialog (this);
            prog.SetProgressStyle(ProgressDialogStyle.Spinner);
            prog.SetMessage(this.GetString(Resource.String.connection_progress));
            prog.Show ();
        }
コード例 #2
0
        /// <summary>
        /// Posts the updated song to the server.  It actually puts formencoded (?!) JSON into the request, which is how I wrote the server for some reason.
        /// </summary>
        /// <returns>
        /// The updated song.
        /// </returns>
        /// <param name='song'>
        /// Song.
        /// </param>
        public Task<Song> PostUpdatedSong(Song song)
        {
            Logging.Debug (c, "Posting song update for song id " + song.Id);
            var req = new RestRequest(String.Format("/songs/{0}", song.Id), Method.POST);
            var task = new TaskCompletionSource<Song>();
            req.AddParameter("song", JsonConvert.SerializeObject(song, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new UnderscorePropertyNamesResolver(), NullValueHandling = NullValueHandling.Ignore }));
            // req.AddParameter("song", JsonConvert
            ExecuteHttpTask(req, "pushing song").ContinueWith((songResult) => {
                try {
                    var updatedSong = DeserializeSong(songResult.Result);
                    task.SetResult (updatedSong);
                } catch (Exception e) {
                    task.SetException(e);
                }

            });
            return task.Task;
        }