void IInternalMusicPlayer.OnLockEvent(object sender, ObjectStateChangeArgs e)
        {
            IInternalTrack ts = sender as IInternalTrack;
            if (ts != _TrackSource)
                throw new Exception("Lock management");

            PlayMode currentmode = Mode;

            switch (e.NewState)
            {

                case ObjectState.Available:
                    if (e.OldState != ObjectState.UnderEdit)
                        break;

                    //liberation de lock
                    if (_Foto == null)
                        return;

                    if ((_Foto.Track != ts) || (currentmode != PlayMode.Paused))
                        throw new Exception("Lock management");
                        
                    bool play = _Foto.PlayOrPaused;
                    if (play)
                    {
                        PlayFromFoto();
                    }
                  
                    break;


                case ObjectState.UnderEdit:

                    //Lock de track
                    switch (currentmode)
                    {
                        case PlayMode.Stopped:
                            RawClose();
                            break;

                        case PlayMode.Play:
                            RawPause();
                            _Foto = new PlayFoto(_TrackSource, Position, true);
                            using (Silent())
                            {
                                RawStop();
                                RawClose();
                            }
                            PrivateMode = PlayMode.Paused;
                            break;


                        case PlayMode.Paused:
                            _Foto = new PlayFoto(_TrackSource, Position, false);
                            using (Silent())
                            {
                                RawStop();
                                RawClose();
                            }
                            break;
                    }
                    break;

                case ObjectState.FileNotAvailable:

                    PlayListtransition();
                    break;
            }

        }
        public void Stop()
        {
            _Foto = null;

            if ((_TrackSource == null) || (_TrackSource.IsBroken))
                return;

            if (_TrackSource.InternalState == ObjectState.UnderEdit)
            {
                PrivateMode = PlayMode.Stopped;
                return;
            }

            using (TrackChanger(PlayMode.Stopped))
            {
                RawStop();
            }
        }
        private void PlayFromFoto()
        {
            if (_Foto == null)
                return;

            string path = _Foto.Track.Path;
            if (FileSource != path)
                FileSource = path;

            TimeSpan cPosition = _Foto.Position;
            ITrack tr = _Foto.Track;
            _Foto = null;

            //bool Done = false;
            IDisposable sil = Silent();
            EventHandler<MusicTrackEventArgs> timeshifter = null;
            double vol = Volume;
            InternalVolume = 0;

            timeshifter = (o, ev) =>
            {
                if ((ev.What == TrackPlayingEvent.BeginPlay) && (object.ReferenceEquals(_TrackSource, tr))) RawPosition = cPosition; InternalVolume = vol; sil.Dispose(); PrivateTrackEvent -= timeshifter;
            };
            PrivateTrackEvent += timeshifter;

            PrivateMode = PlayMode.Play;
            RawPlay();
        }