示例#1
0
 public override void OnSaveInstanceState(Android.OS.Bundle outState)
 {
     base.OnSaveInstanceState(outState);
     if (CurrentRun != null)
     {
         outState.PutInt(RUN_ID, CurrentRun.Id);
     }
 }
示例#2
0
            override public bool OnControlRequest(Intent intent, Android.Support.V7.Media.MediaRouter.ControlRequestCallback callback)
            {
                Android.Util.Log.Debug(TAG, mRouteId + ": Received control request " + intent);
                if (intent.Action.Equals(MediaControlIntent.ActionPlay) &&
                    intent.HasCategory(MediaControlIntent.CategoryRemotePlayback) &&
                    intent.Data != null)
                {
                    mOutterClass.mPlaybackCount += 1;

                    // TODO: Handle queue ids.
                    var  uri = intent.Data;
                    long contentPositionMillis = intent.GetLongExtra(
                        MediaControlIntent.ExtraItemContentPosition, 0);
                    var metadata = intent.GetBundleExtra(MediaControlIntent.ExtraItemMetadata);
                    var headers  = intent.GetBundleExtra(
                        MediaControlIntent.ExtraItemHttpHeaders);

                    Android.Util.Log.Debug(TAG, mRouteId + ": Received play request, uri=" + uri
                                           + ", contentPositionMillis=" + contentPositionMillis
                                           + ", metadata=" + metadata
                                           + ", headers=" + headers);

                    if (uri.ToString().Contains("hats"))
                    {
                        // Simulate generating an error whenever the uri contains the word 'hats'.
                        Android.Widget.Toast.MakeText(mOutterClass.Context, "Route rejected play request: uri=" + uri
                                                      + ", no hats allowed!", Android.Widget.ToastLength.Long).Show();
                        if (callback != null)
                        {
                            callback.OnError("Simulated error.  No hats allowed!", null);
                        }
                    }
                    else
                    {
                        Android.Widget.Toast.MakeText(mOutterClass.Context, "Route received play request: uri=" + uri,
                                                      Android.Widget.ToastLength.Long).Show();
                        string streamId = mOutterClass.GenerateStreamId();
                        if (callback != null)
                        {
                            MediaItemStatus status = new MediaItemStatus.Builder(
                                MediaItemStatus.PlaybackStatePlaying)
                                                     .SetContentPosition(contentPositionMillis)
                                                     .Build();

                            var result = new Android.OS.Bundle();
                            result.PutString(MediaControlIntent.ExtraItemId, streamId);
                            result.PutString(MediaControlIntent.ExtraItemStatus, status.AsBundle().ToString());
                            callback.OnResult(result);
                        }
                    }
                    return(true);
                }

                if (intent.Action.Equals(ACTION_GET_STATISTICS) &&
                    intent.HasCategory(CATEGORY_SAMPLE_ROUTE))
                {
                    var data = new Android.OS.Bundle();
                    data.PutInt(DATA_PLAYBACK_COUNT, mOutterClass.mPlaybackCount);
                    if (callback != null)
                    {
                        callback.OnResult(data);
                    }
                    return(true);
                }


                return(false);
            }