Exemple #1
0
        public LoginViewModel(IPageSwitchingService pageSwitchingService, IEventAggregator eventAggregator, IAudioStationSession audioStationSession, IOpenSynoSettings synoSettings, ISignInService signInService, IPlaybackService playbackService)
        {
            if (pageSwitchingService == null) throw new ArgumentNullException("pageSwitchingService");
            if (eventAggregator == null) throw new ArgumentNullException("eventAggregator");
            if (audioStationSession == null) throw new ArgumentNullException("audioStationSession");
            SignInCommand = new DelegateCommand(OnSignIn);
            _pageSwitchingService = pageSwitchingService;
            _eventAggregator = eventAggregator;
            _audioStationSession = audioStationSession;
            _synoSettings = synoSettings;
            _signInService = signInService;
            _signInService.SignInCompleted += OnSignInCompleted;

            // Unregister the registered events to make sure we don't execute the event handler twice in case of exceptions
            _signInService.CheckTokenValidityCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    _signInService.CheckTokenValidityCompleted -= OnCheckTokenValidityCompleted;
                }
            };

            _playbackService = playbackService;
            UserName = _synoSettings.UserName;
            UseSsl = _synoSettings.UseSsl;
            Password = _synoSettings.Password;
            Host = _synoSettings.Host;
            Port = _synoSettings.Port;
        }
Exemple #2
0
        public TrackViewModel(Guid guid, SynoTrack synoTrack, IPageSwitchingService pageSwitchingService, AlbumViewModelFactory albumViewModelFactory, IAudioStationSession session, IUrlParameterToObjectsPlateHeater urlParameterToObjectsPlateHeater, ITrackViewModelFactory trackViewModelFactory, INotificationService notificationService)
        {
            if (synoTrack == null)
            {
                throw new ArgumentNullException("synoTrack");
            }

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            _trackViewModelFactory = trackViewModelFactory;
            _notificationService   = notificationService;

            if (albumViewModelFactory == null)
            {
                throw new ArgumentNullException("albumViewModelFactory");
            }

            Guid      = guid;
            TrackInfo = synoTrack;

            NavigateToContainingAlbumCommand = new DelegateCommand(OnNavigateToContainingAlbum);

            this._session = session;
            this._urlParameterToObjectsPlateHeater = urlParameterToObjectsPlateHeater;
            _albumViewModelFactory = albumViewModelFactory;
            _albumViewModelFactory = albumViewModelFactory;
            _pageSwitchingService  = pageSwitchingService;
        }
Exemple #3
0
        public TrackViewModel(Guid guid, SynoTrack synoTrack, IPageSwitchingService pageSwitchingService, AlbumViewModelFactory albumViewModelFactory, IAudioStationSession session, IUrlParameterToObjectsPlateHeater urlParameterToObjectsPlateHeater, ITrackViewModelFactory trackViewModelFactory, INotificationService notificationService)
        {
            if (synoTrack == null)
            {
                throw new ArgumentNullException("synoTrack");
            }

            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            _trackViewModelFactory = trackViewModelFactory;
            _notificationService = notificationService;

            if (albumViewModelFactory == null) throw new ArgumentNullException("albumViewModelFactory");

            Guid = guid;
            TrackInfo = synoTrack;

            NavigateToContainingAlbumCommand = new DelegateCommand(OnNavigateToContainingAlbum);

            this._session = session;
            this._urlParameterToObjectsPlateHeater = urlParameterToObjectsPlateHeater;
            _albumViewModelFactory = albumViewModelFactory;
            _albumViewModelFactory = albumViewModelFactory;
            _pageSwitchingService = pageSwitchingService;
        }
        public AudioRenderingService(IAudioStationSession audioStationSession)
        {
            // todo : inject ?
            _logService = IoC.Container.Get <ILogService>();

            _logService.Trace("AudioRenderingService .ctor");
            if (audioStationSession == null)
            {
                throw new ArgumentNullException("audioStationSession");
            }
            _audioStationSession = audioStationSession;

            //_mediaElement = (MediaElement)Application.Current.Resources["MediaElement"];

            BufferPlayableHeuristicPredicate = (track, bytesLoaded) => bytesLoaded >= track.Bitrate || bytesLoaded == track.Size;

            //_mediaElement.MediaFailed += MediaFailed;

            // TODO : Add error handling

            // TODO : Add position handling BackgroundAudioPlayer.Instance.Position
            // _mediaElement.SetBinding(MediaElement.PositionProperty, new Binding { Source = this, Mode = BindingMode.TwoWay, Path = new PropertyPath(PositionPropertyName)  });

            // todo : handle state changes
            // _mediaElement.CurrentStateChanged += OnCurrentStateChanged;

            //_mediaElement.MediaOpened += MediaOpened;

            // todo : handle end of track
            //_mediaElement.MediaEnded += PlayingMediaEnded;
        }
        public AudioRenderingService(IAudioStationSession audioStationSession)
        {
            // todo : inject ?
            _logService = IoC.Container.Get<ILogService>();

            _logService.Trace("AudioRenderingService .ctor");
            if (audioStationSession == null)
            {
                throw new ArgumentNullException("audioStationSession");
            }
            _audioStationSession = audioStationSession;

            //_mediaElement = (MediaElement)Application.Current.Resources["MediaElement"];

            BufferPlayableHeuristicPredicate = (track, bytesLoaded) =>  bytesLoaded >= track.Bitrate||  bytesLoaded == track.Size;

            //_mediaElement.MediaFailed += MediaFailed;

            // TODO : Add error handling

            // TODO : Add position handling BackgroundAudioPlayer.Instance.Position
            // _mediaElement.SetBinding(MediaElement.PositionProperty, new Binding { Source = this, Mode = BindingMode.TwoWay, Path = new PropertyPath(PositionPropertyName)  });

            // todo : handle state changes
            // _mediaElement.CurrentStateChanged += OnCurrentStateChanged;

            //_mediaElement.MediaOpened += MediaOpened;

            // todo : handle end of track
            //_mediaElement.MediaEnded += PlayingMediaEnded;
        }
 public TrackViewModelFactory(IAudioStationSession session, IUrlParameterToObjectsPlateHeater urlParameterToObjectsPlateHeater, AlbumViewModelFactory albumViewModelFactory, INotificationService notificationService)
 {
     if (session == null) throw new ArgumentNullException("session");
     if (urlParameterToObjectsPlateHeater == null)
         throw new ArgumentNullException("urlParameterToObjectsPlateHeater");
     if (albumViewModelFactory == null) throw new ArgumentNullException("albumViewModelFactory");
     this._session = session;
     this._urlParameterToObjectsPlateHeater = urlParameterToObjectsPlateHeater;
     _albumViewModelFactory = albumViewModelFactory;
     this.notificationService = notificationService;
 }
 public TrackViewModelFactory(IAudioStationSession session, IUrlParameterToObjectsPlateHeater urlParameterToObjectsPlateHeater, AlbumViewModelFactory albumViewModelFactory, INotificationService notificationService)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (urlParameterToObjectsPlateHeater == null)
     {
         throw new ArgumentNullException("urlParameterToObjectsPlateHeater");
     }
     if (albumViewModelFactory == null)
     {
         throw new ArgumentNullException("albumViewModelFactory");
     }
     this._session = session;
     this._urlParameterToObjectsPlateHeater = urlParameterToObjectsPlateHeater;
     _albumViewModelFactory   = albumViewModelFactory;
     this.notificationService = notificationService;
 }
Exemple #8
0
        public LoginViewModel(IPageSwitchingService pageSwitchingService, IEventAggregator eventAggregator, IAudioStationSession audioStationSession, IOpenSynoSettings synoSettings, ISignInService signInService, IPlaybackService playbackService)
        {
            if (pageSwitchingService == null)
            {
                throw new ArgumentNullException("pageSwitchingService");
            }
            if (eventAggregator == null)
            {
                throw new ArgumentNullException("eventAggregator");
            }
            if (audioStationSession == null)
            {
                throw new ArgumentNullException("audioStationSession");
            }
            SignInCommand                   = new DelegateCommand(OnSignIn);
            _pageSwitchingService           = pageSwitchingService;
            _eventAggregator                = eventAggregator;
            _audioStationSession            = audioStationSession;
            _synoSettings                   = synoSettings;
            _signInService                  = signInService;
            _signInService.SignInCompleted += OnSignInCompleted;

            // Unregister the registered events to make sure we don't execute the event handler twice in case of exceptions
            _signInService.CheckTokenValidityCompleted += (o, e) =>
            {
                if (e.Error != null)
                {
                    _signInService.CheckTokenValidityCompleted -= OnCheckTokenValidityCompleted;
                }
            };

            _playbackService = playbackService;
            UserName         = _synoSettings.UserName;
            UseSsl           = _synoSettings.UseSsl;
            Password         = _synoSettings.Password;
            Host             = _synoSettings.Host;
            Port             = _synoSettings.Port;
        }
Exemple #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlaybackService"/> class.
        /// </summary>
        /// <param name="audioStationSession"></param>
        /// <param name="audioTrackFactory"></param>
        public PlaybackService(IAudioStationSession audioStationSession, IAudioTrackFactory audioTrackFactory, IVersionDependentResourcesProvider versionDependentResourceProvider)
        {
            _logService = IoC.Container.Get <ILogService>();

            _audioStationSession = audioStationSession;
            _audioTrackFactory   = audioTrackFactory;
            _versionDependentResourceProvider = versionDependentResourceProvider;

            // We need an observable collection so we can serialize the items to IsolatedStorage in order to get the background rendering service to read it from disk, since the background Agent is not running in the same process.
            //PlayqueueItems = new ObservableCollection<ISynoTrack>();

            this._tracksToGuidMapping = new List <GuidToTrackMapping>();

            using (var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (
                    IsolatedStorageFileStream asciiUriFixes = userStoreForApplication.OpenFile(
                        "AsciiUriFixes.xml", FileMode.OpenOrCreate))
                {
                    DataContractSerializer dcs = new DataContractSerializer(typeof(List <AsciiUriFix>));
                    //var xs = new XmlSerializer(typeof(PlayqueueInterProcessCommunicationTransporter));

                    try
                    {
                        _asciiUriFixes = (List <AsciiUriFix>)dcs.ReadObject(asciiUriFixes);
                    }
                    catch (Exception e)
                    {
                        // could not deserialize XML for playlist : let's build an empty list.
                        _asciiUriFixes = new List <AsciiUriFix>();
                    }
                }

                PlayqueueInterProcessCommunicationTransporter deserialization = null;
                using (
                    IsolatedStorageFileStream playQueueFile = userStoreForApplication.OpenFile(
                        "playqueue.xml", FileMode.OpenOrCreate))
                {
                    DataContractSerializer dcs =
                        new DataContractSerializer(typeof(PlayqueueInterProcessCommunicationTransporter));
                    //var xs = new XmlSerializer(typeof(PlayqueueInterProcessCommunicationTransporter));

                    try
                    {
                        deserialization = (PlayqueueInterProcessCommunicationTransporter)dcs.ReadObject(playQueueFile);

                        foreach (GuidToTrackMapping pair in deserialization.Mappings)
                        {
                            this._tracksToGuidMapping.Add(pair);
                        }
                    }
                    catch (Exception e)
                    {
                        // could not deserialize XML for playlist : let's keep it empty.
                    }
                }
            }


            //this.PlayqueueItems.CollectionChanged += this.OnPlayqueueItemsChanged;

            BackgroundAudioPlayer.Instance.PlayStateChanged += new EventHandler(this.BackgroundPlayerPlayStateChanged);

            this._progressUpdater = new Timer(
                e =>
            {
                var backgroundAudioPlayer = BackgroundAudioPlayer.Instance;
                if (this.TrackCurrentPositionChanged != null && backgroundAudioPlayer.Track != null)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        TrackCurrentPositionChangedEventArgs trackCurrentPositionChangedEventArgs = new TrackCurrentPositionChangedEventArgs();

                        trackCurrentPositionChangedEventArgs.LoadPercentComplete = backgroundAudioPlayer.BufferingProgress;
                        double totalSeconds = 0;
                        TimeSpan position   = new TimeSpan();

                        try
                        {
                            position = backgroundAudioPlayer.Position;
                        }
                        catch (SystemException)
                        {
                            _progressUpdater.Change(-1, 0);
                            // swallow exception : we get an HRESULT error, when no valid position could be retrieved. Maybe a beta behavior that will change in the future. since we can ignore the error and set the duration to 0 ( maybe the track hasn't been loaded yet ) we'll just swallow the exception.
                        }

                        try
                        {
                            totalSeconds = backgroundAudioPlayer.Position.TotalSeconds;
                        }
                        catch (SystemException)
                        {
                            // swallow exception : we get an HRESULT error, when no valid duration could be retrieved. Maybe a beta behavior that will change in the future. since we can ignore the error and set the duration to 0 ( maybe the track hasn't been loaded yet ) we'll just swallow the exception.
                        }

                        if (position.TotalSeconds == 0)
                        {
                            // avoid zero-division
                            trackCurrentPositionChangedEventArgs.PlaybackPercentComplete = 0;
                        }
                        else
                        {
                            trackCurrentPositionChangedEventArgs.PlaybackPercentComplete = totalSeconds / backgroundAudioPlayer.Track.Duration.TotalSeconds;
                            trackCurrentPositionChangedEventArgs.Position = position;
                        }

                        this.TrackCurrentPositionChanged(this, trackCurrentPositionChangedEventArgs);
                    });
                }
            },
                null,
                0,
                200);
            //(o, e) =>
            //{
            //    _backgroundAudioRenderingService.OnPlayqueueItemsChanged(e.NewItems, e.OldItems);
            //};
        }
Exemple #10
0
 public SearchService(IAudioStationSession audioStationSession)
 {
     _audioStationSession = audioStationSession;
 }
Exemple #11
0
 public SearchService(IAudioStationSession audioStationSession)
 {
     _audioStationSession = audioStationSession;
 }
Exemple #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlaybackService"/> class.
        /// </summary>
        /// <param name="audioStationSession"></param>
        /// <param name="audioTrackFactory"></param>
        public PlaybackService(IAudioStationSession audioStationSession, IAudioTrackFactory audioTrackFactory, IVersionDependentResourcesProvider versionDependentResourceProvider)
        {
            _logService = IoC.Container.Get<ILogService>();

            _audioStationSession = audioStationSession;
            _audioTrackFactory = audioTrackFactory;
            _versionDependentResourceProvider = versionDependentResourceProvider;

            // We need an observable collection so we can serialize the items to IsolatedStorage in order to get the background rendering service to read it from disk, since the background Agent is not running in the same process.
            //PlayqueueItems = new ObservableCollection<ISynoTrack>();

            this._tracksToGuidMapping = new List<GuidToTrackMapping>();

            using (var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
            {

                using (
                    IsolatedStorageFileStream asciiUriFixes = userStoreForApplication.OpenFile(
                        "AsciiUriFixes.xml", FileMode.OpenOrCreate))
                {

                    DataContractSerializer dcs = new DataContractSerializer(typeof(List<AsciiUriFix>));
                    //var xs = new XmlSerializer(typeof(PlayqueueInterProcessCommunicationTransporter));

                    try
                    {
                        _asciiUriFixes = (List<AsciiUriFix>)dcs.ReadObject(asciiUriFixes);
                    }
                    catch (Exception e)
                    {
                        // could not deserialize XML for playlist : let's build an empty list.
                        _asciiUriFixes = new List<AsciiUriFix>();
                    }
                }

                PlayqueueInterProcessCommunicationTransporter deserialization = null;
                using (
                    IsolatedStorageFileStream playQueueFile = userStoreForApplication.OpenFile(
                        "playqueue.xml", FileMode.OpenOrCreate))
                {

                    DataContractSerializer dcs =
                        new DataContractSerializer(typeof(PlayqueueInterProcessCommunicationTransporter));
                    //var xs = new XmlSerializer(typeof(PlayqueueInterProcessCommunicationTransporter));

                    try
                    {
                        deserialization = (PlayqueueInterProcessCommunicationTransporter)dcs.ReadObject(playQueueFile);

                        foreach (GuidToTrackMapping pair in deserialization.Mappings)
                        {
                            this._tracksToGuidMapping.Add(pair);
                        }
                    }
                    catch (Exception e)
                    {
                        // could not deserialize XML for playlist : let's keep it empty.

                    }
                }
            }

            //this.PlayqueueItems.CollectionChanged += this.OnPlayqueueItemsChanged;

            BackgroundAudioPlayer.Instance.PlayStateChanged += new EventHandler(this.BackgroundPlayerPlayStateChanged);

            this._progressUpdater = new Timer(
                e =>
                {
                    var backgroundAudioPlayer = BackgroundAudioPlayer.Instance;
                    if (this.TrackCurrentPositionChanged != null && backgroundAudioPlayer.Track != null)
                    {

                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                            {
                                TrackCurrentPositionChangedEventArgs trackCurrentPositionChangedEventArgs = new TrackCurrentPositionChangedEventArgs();

                                trackCurrentPositionChangedEventArgs.LoadPercentComplete = backgroundAudioPlayer.BufferingProgress;
                                double totalSeconds = 0;
                                TimeSpan position = new TimeSpan();

                                try
                                {
                                    position = backgroundAudioPlayer.Position;
                                }
                                catch (SystemException)
                                {
                                    _progressUpdater.Change(-1, 0);
                                    // swallow exception : we get an HRESULT error, when no valid position could be retrieved. Maybe a beta behavior that will change in the future. since we can ignore the error and set the duration to 0 ( maybe the track hasn't been loaded yet ) we'll just swallow the exception.
                                }

                                try
                                {
                                    totalSeconds = backgroundAudioPlayer.Position.TotalSeconds;
                                }
                                catch (SystemException)
                                {
                                    // swallow exception : we get an HRESULT error, when no valid duration could be retrieved. Maybe a beta behavior that will change in the future. since we can ignore the error and set the duration to 0 ( maybe the track hasn't been loaded yet ) we'll just swallow the exception.
                                }

                                if (position.TotalSeconds == 0)
                                {
                                    // avoid zero-division
                                    trackCurrentPositionChangedEventArgs.PlaybackPercentComplete = 0;
                                }
                                else
                                {
                                    trackCurrentPositionChangedEventArgs.PlaybackPercentComplete = totalSeconds / backgroundAudioPlayer.Track.Duration.TotalSeconds;
                                    trackCurrentPositionChangedEventArgs.Position = position;
                                }

                                this.TrackCurrentPositionChanged(this, trackCurrentPositionChangedEventArgs);
                            });
                    }
                },
                null,
                0,
                200);
            //(o, e) =>
            //{
            //    _backgroundAudioRenderingService.OnPlayqueueItemsChanged(e.NewItems, e.OldItems);
            //};
        }