Exemplo n.º 1
0
        void ButtonStart_Clicked(object sender, EventArgs e)
        {
            var player = ((MainPageViewModel)BindingContext).MediaPlayer;

            player.TimeChanged -= TimeChanged;
            player.TimeChanged += TimeChanged;

            var playerData = new MediaPlayerData
            {
                //VideoTrackDescription = player.VideoTrackDescription,
                //VideoTrackCount = player.VideoTrackCount,
                //VideoTrack = player.VideoTrack,
                State = player.State,
                //Spu = player.Spu,
                //Position = player.Position,
                //AudioTrack = player.AudioTrack,
                //AudioTrackCount = player.AudioTrackCount,
                //AudioTrackDescription = player.AudioTrackDescription,
                //Channel = player.Channel,
                //Media = player.Media,
                Time = player.Time
            };
            var message = new StartLongRunningTaskMessage <MediaPlayerData> {
                TaskData = playerData
            };

            MessagingCenter.Send(message, "StartLongRunningTaskMessage");
        }
Exemplo n.º 2
0
        private void ReInitialisePlayer(MediaPlayerData data)
        {
            var mediaPlayer = ((MainPageViewModel)BindingContext).MediaPlayer;

            mediaPlayer?.Stop();

            //((MainPageViewModel)BindingContext).Initialize();
            //mediaPlayer = ((MainPageViewModel)BindingContext).MediaPlayer;
            mediaPlayer.Play();
            mediaPlayer.Time = AppCode_Shared.Settings.currentTime;
        }
Exemplo n.º 3
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            _cts = new CancellationTokenSource();

            Task.Run(() =>
            {
                try
                {
                    //INVOKE THE SHARED CODE
                    var backgroundwork = new MediaBackgroundWork();
                    //Call any background method needed here
                    backgroundwork.LogMediaState(_cts.Token).Wait();
                    //as of now background work methods are empty, if you need you can use//
                }
                catch (System.OperationCanceledException ex)
                {
                    Toast.MakeText(this, ex.Message.ToString(), ToastLength.Short);
                }
                finally
                {
                    if (_cts.IsCancellationRequested)
                    {
                        var message = new CancelledMessage();
                        Device.BeginInvokeOnMainThread(
                            () => MessagingCenter.Send(message, "CancelledMessage")
                            );
                    }
                }
            }, _cts.Token);


            // Enlist this instance of the service as a foreground service
            var             builder = _MakeNotificationBuilder();
            MediaPlayerData data    = JsonConvert.DeserializeObject <MediaPlayerData>(intent.GetStringExtra(Settings.ValueTranferKey));

            builder.SetContentText("Media playing");
            builder.SetContentIntent(_MakePendingIntent(intent));
            livenotific = builder.Build();
            StartForeground(SERVICE_RUNNING_NOTIFICATION_ID, livenotific);
            return(StartCommandResult.Sticky);
        }