private void _musicPlayer_OnReceiveMessage(Windows.Foundation.Collections.ValueSet message)
        {
            TrackChangedMessage trackChangedMessage;

            if (MessageService.TryParseMessage(message, out trackChangedMessage))
            {
                // When foreground app is active change track based on background message
                _playerSession?.NotifyCurrentTrackChanged(_playlist?.FirstOrDefault(s => s.Source == trackChangedMessage.TrackId));
                _currentTrack = _playlist.FirstOrDefault(s => s.Source == trackChangedMessage.TrackId);
            }
        }
Beispiel #2
0
        public async Task <Windows.Foundation.Collections.ValueSet> MakeUWPCommandCall(string commandCall, string serviceName, List <KeyValuePair <string, object> > dataToPass)
        {
            using (var connection = new Windows.ApplicationModel.AppService.AppServiceConnection())
            {
                connection.AppServiceName    = serviceName;
                connection.PackageFamilyName = HostPackageFamilyName;
                var status = await connection.OpenAsync();

                if (status != Windows.ApplicationModel.AppService.AppServiceConnectionStatus.Success)
                {
                    throw new NotImplementedException("Failed app service connection");
                }
                else
                {
                    var request = new Windows.Foundation.Collections.ValueSet();
                    request.Add("Command", commandCall);

                    if (dataToPass != null && dataToPass.Count > 0)
                    {
                        foreach (var data in dataToPass)
                        {
                            //message.Add(new KeyValuePair<string, object>("AppExtensionDisplayName", AppExtension.AppInfo.DisplayInfo.DisplayName));
                            request.Add(new KeyValuePair <string, object>(data.Key, data.Value));
                        }
                    }

                    Windows.ApplicationModel.AppService.AppServiceResponse response = await connection.SendMessageAsync(request);

                    if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success)
                    {
                        var message = response.Message as Windows.Foundation.Collections.ValueSet;
                        if (message != null && message.Count > 0)
                        {
                        }
                        return((message != null && message.Count > 0) ? message : null);
                    }
                }
            }
            return(null);
        }
Beispiel #3
0
        public async Task<Windows.Foundation.Collections.ValueSet> MakeUWPCommandCall(string commandCall, string serviceName, List<KeyValuePair<string, object>> dataToPass)
        {

            using (var connection = new Windows.ApplicationModel.AppService.AppServiceConnection())
            {
                connection.AppServiceName = serviceName;
                connection.PackageFamilyName = HostPackageFamilyName;
                var status = await connection.OpenAsync();
                if (status != Windows.ApplicationModel.AppService.AppServiceConnectionStatus.Success)
                {
                    throw new NotImplementedException("Failed app service connection");
                }
                else
                {
                    var request = new Windows.Foundation.Collections.ValueSet();
                    request.Add("Command", commandCall);

                    if (dataToPass != null && dataToPass.Count > 0)
                    {
                        foreach (var data in dataToPass)
                        {
                            //message.Add(new KeyValuePair<string, object>("AppExtensionDisplayName", AppExtension.AppInfo.DisplayInfo.DisplayName));
                            request.Add(new KeyValuePair<string, object>(data.Key, data.Value));
                        }
                    }

                    Windows.ApplicationModel.AppService.AppServiceResponse response = await connection.SendMessageAsync(request);
                    if (response.Status == Windows.ApplicationModel.AppService.AppServiceResponseStatus.Success)
                    {
                        var message = response.Message as Windows.Foundation.Collections.ValueSet;
                        if (message != null && message.Count > 0)
                        {
                            
                        }
                        return (message != null && message.Count > 0) ? message : null;
                    }
                }

            }
            return null;
        }