/// <summary> /// Fired when MediaPlayer is ready to play the track /// </summary> private void MediaPlayer_MediaOpened(MediaPlayer sender, object args) { // wait for media to be ready sender.Play(); if (CurrentTrack == null) { return; } Debug.WriteLine("New Track" + CurrentTrack.Song.Name); if (TrackChanged != null) { TrackChanged.Invoke(this, CurrentTrack.SongId); } try { CurrentTrack.Song.PlayCount++; CurrentTrack.Song.LastPlayed = DateTime.Now; _sql.UpdateItemAsync(CurrentTrack.Song).Wait(); } catch { } }
public void Push(PlexTrack track) { lock (tracks) tracks.AddFirst(track); TrackChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// Raised when a message is recieved from the foreground app /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BackgroundMediaPlayer_MessageReceivedFromForeground(object sender, MediaPlayerDataReceivedEventArgs e) { var message = MessageHelper.ParseMessage(e.Data); if (message is AppSuspendedMessage) { AppSuspended?.Invoke(this, null); } else if (message is AppResumedMessage) { AppResumed?.Invoke(this, null); } else if (message is StartPlaybackMessage) { StartPlayback?.Invoke(this, null); } else if (message is SkipNextMessage) { SkipToNext?.Invoke(this, null); } else if (message is SkipPreviousMessage) { SkipToPrev?.Invoke(this, null); } else { var changedMessage = message as TrackChangedMessage; if (changedMessage != null) { TrackChanged?.Invoke(this, changedMessage.QueueId); } else { var playlistMessage = message as UpdatePlaylistMessage; if (playlistMessage != null) { UpdatePlaylist?.Invoke(this, playlistMessage.Tracks); } else { var addMessage = message as AddToPlaylistMessage; if (addMessage != null) { AddToPlaylist?.Invoke(addMessage.Tracks, addMessage.Position); } else { var updateMessage = message as UpdateUrlMessage; if (updateMessage != null) { TrackUpdateUrl?.Invoke(this, updateMessage); } } } } } }
public void Rearrange(int from, int to) { lock (tracks) { // rearrange var track = tracks[from]; tracks.RemoveAt(from); tracks.Insert(to, track); // reset ResetPlayedIndexes(); // fix current if (from <= Current || to <= Current) { if (from == Current) { current = to; } else if (to > Current) { current--; } else if (to <= Current) { current++; } } } TrackChanged?.Invoke(this, new EventArgs()); }
void HandleMediaPlayerMediaOpened(MediaPlayer sender, object args) { if (isFirstOpen) { isFirstOpen = false; double percentage = ApplicationSettings.GetSettingsValue <double>(ApplicationSettings.CURRENT_TRACK_PERCENTAGE, 0.0); ApplicationSettings.PutSettingsValue(ApplicationSettings.CURRENT_TRACK_PERCENTAGE, 0.0); if (percentage > 0) { Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Length Total {0}", mediaPlayer.NaturalDuration.Ticks); mediaPlayer.Position = TimeSpan.FromTicks((long)(mediaPlayer.NaturalDuration.Ticks * percentage)); } } int trackId = ApplicationSettings.GetSettingsValue <int>(ApplicationSettings.CURRENT_PLAYQUEUE_POSITION, 0); Logger.Current.Log(new CallerInfo(), LogLevel.Info, "Trying to play row {0}", trackId); playingTrack = TrackInfo.TrackInfoFromRowId(trackId); TrackChanged.Invoke(this, playingTrack); if (playAfterOpen) { sender.Play(); } else { playAfterOpen = true; } }
public void Rearrange(int from, int to) { if (from == to) { return; } lock (tracks) { // remove var track = Remove(from); // get node by index LinkedListNode <PlexTrack> trackNode = tracks.First; for (int i = 0; i < to && trackNode != null; i++) { trackNode = trackNode.Next; } if (trackNode == null) { tracks.AddLast(track); } else { tracks.AddBefore(trackNode, track); } } TrackChanged?.Invoke(this, new EventArgs()); }
private async Task OpenPlayable(IPlayable playable, IPlaylist playlist, bool openPlaying, bool openCrossfading, bool addToTempHistory) { _isOpeningTrack = true; if (CurrentTrack != null) { TrackChanged?.Invoke(this, new TrackChangedEventArgs(CurrentTrack, AudioEngine.TimePlaySourcePlayed)); } CurrentTrack = playable; CurrentPlaylist = playlist; if (await AudioEngine.OpenTrack(await playable.GetSoundSource(), IsCrossfadeEnabled && openCrossfading, 0)) { var track = playable as PlayableBase; if (track != null) { playlist?.GetBackHistory().Add(track); } NewTrackOpened?.Invoke(this, new NewTrackOpenedEventArgs(playable)); if (addToTempHistory && (_tempHistory.Count == 0 || _tempHistory.Last().Item1 != playlist || _tempHistory.Last().Item2 != playable)) { _tempHistory.Add(Tuple.Create(playlist, playable)); } if (openPlaying && !(IsCrossfadeEnabled && openCrossfading)) { await AudioEngine.TogglePlayPause(); } } _isOpeningTrack = false; }
public PlexTrack FromTracks(PlexTrack[] tracks, int current = -1) { lock (tracks) { this.tracks.Clear(); foreach (var track in tracks) { this.tracks.Add(track); } } if (current < 0) { var playback = PlaybackManager.GetInstance(); current = playback.IsShuffle ? new Random().Next(0, this.tracks.Count - 1) : current; } ResetPlayedIndexes(); var currentTrack = Play(current); TrackChanged?.Invoke(this, new EventArgs()); return(currentTrack); }
/// <summary> /// 接收到后台消息时的event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BackgroundMediaPlayer_MessageReceivedFromBackground(object sender, MediaPlayerDataReceivedEventArgs e) { lock (o) { TrackChangeMessage trackChangeMessage; if (MessageService.TryParseMessage(e.Data, out trackChangeMessage)) { TrackChangedEventArgs args = new TrackChangedEventArgs(); args.OldTrack = CurrentPlayingIndex; args.NewTrack = trackChangeMessage.TrackIndex; TrackChanged?.Invoke(this, args); DispatcherHelper.CheckBeginInvokeOnUI(() => { new ViewModelLocator().Main.CurrentIndex = trackChangeMessage.TrackIndex; }); CurrentPlayingIndex = trackChangeMessage.TrackIndex; //int index = Playlist.FindIndex(p => p.FileName == trackChangeMessage.TrackFile); //TrackChangedEventArgs args = new TrackChangedEventArgs(); //args.OldTrack = CurrentPlayingIndex; //args.NewTrack = index; //TrackChanged?.Invoke(this, args); //CurrentPlayingIndex = index; return; } BackgroundAudioTaskStopedMessage backgroundAudioTaskStopedMessage; if (MessageService.TryParseMessage(e.Data, out backgroundAudioTaskStopedMessage)) { return; } } }
/// <summary> /// Fired when MediaPlayer is ready to play the track /// </summary> void MediaPlayer_MediaOpened(MediaPlayer sender, object args) { // wait for media to be ready sender.Play(); Debug.WriteLine("Track Change! New Track is: " + this.CurrentTrackName); TrackChanged.Invoke(this, "Vocaloid Radio"); }
private void MediaPlayer_MediaOpened(MediaPlayer sender, object args) { // wait for media to be ready sender.Play(); Debug.WriteLine("New Track" + CurrentTrackName); TrackChanged.Invoke(this, CurrentTrackName); }
public PlexTrack Remove(int index) { LinkedListNode <PlexTrack> trackNode = tracks.First; lock (tracks) { for (int i = 0; i < index && trackNode != null; i++) { trackNode = trackNode.Next; } if (trackNode != null) { tracks.Remove(trackNode); } } if (trackNode == null) { return(null); } TrackChanged?.Invoke(this, new EventArgs()); return(trackNode.Value); }
private void Current_MediaOpened(MediaPlayer sender, object args) { //wait for media to be ready //sender.Play(); TrackChanged?.Invoke(this, CurrentTrack?.Id); }
private void OnTrackChanged(object sender, TrackChangeEventArgs e) { if (TrackChanged != null) { TrackChanged.Invoke(this, new EventArgs()); } }
private void beatmapChanged(ValueChangedEvent <WorkingBeatmap> beatmap) { TrackChangeDirection direction = TrackChangeDirection.None; if (current != null) { bool audioEquals = beatmap.NewValue?.BeatmapInfo?.AudioEquals(current.BeatmapInfo) ?? false; if (audioEquals) { direction = TrackChangeDirection.None; } else if (queuedDirection.HasValue) { direction = queuedDirection.Value; queuedDirection = null; } else { // figure out the best direction based on order in playlist. var last = BeatmapSets.TakeWhile(b => b.ID != current.BeatmapSetInfo?.ID).Count(); var next = beatmap.NewValue == null ? -1 : BeatmapSets.TakeWhile(b => b.ID != beatmap.NewValue.BeatmapSetInfo?.ID).Count(); direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next; } } current = beatmap.NewValue; TrackChanged?.Invoke(current, direction); ResetTrackAdjustments(); queuedDirection = null; }
private async void PlayerService_TrackChanged(IPlayerService sender, TrackChangedEventArgs e) { _currentTrackId = e.TrackID; if (Tracks == null) { return; } if (_currentTrackId >= 0) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (CurrentTrack != null) { CurrentTrack.IsCurrent = false; } CurrentTrack = Tracks[_currentTrackId]; CurrentTrack.IsCurrent = true; _position = TimeSpan.Zero; OnPropertyChanged(nameof(Position)); Duration = TimeSpan.FromSeconds(1); TrackChanged?.Invoke(this, CurrentTrack); ShowLyricsCommand.RaiseCanExecuteChanged(); DownloadTrackCommand.RaiseCanExecuteChanged(); }); LoadArtistImage(CurrentTrack.Track); LoadTrackImage(CurrentTrack.Track); } }
/// <summary> /// Fired when MediaPlayer is ready to play the track /// </summary> void MediaPlayer_MediaOpened(MediaPlayer sender, object args) { // wait for media to be ready sender.Play(); Debug.WriteLine("New Track" + this.CurrentTrackName); TrackChanged.Invoke(this, !string.IsNullOrEmpty(this.fileName) ? this.fileName : CurrentTrackName); }
private void OnTrackChanged(int channelId, T track) { TrackChanged?.Invoke(this, new TrackChangedEvent <T> { Track = track, ChannelId = channelId }); }
protected virtual void OnTrackChanged(int channelId, Track track) { TrackChanged?.Invoke(this, new TrackChange { Track = track, ChannelId = channelId }); }
private void OnTrackChanged(string channel, ITrack current, ITrack next) { TrackChanged?.Invoke(this, new TrackChanged <ITrack> { Channel = channel, Current = current, Next = next }); }
/// <summary> /// A public method allowing modules to give input csv files to the TrackModel. This method /// takes the input files and parses them for insertion into the database. /// </summary> /// <param name="fName">The file name of the file to be parsed</param> /// <returns>A boolean corresponding to the success or failure of the file parsing and insertion</returns> public bool provideInputFile(string fName) { if (fName == null) { return(false); } if (!fName.EndsWith(".csv")) { return(false); } //Check if file is already in db, if so return true if (fName.Contains("red") || fName.Contains("RED") || fName.Contains("Red")) { if (_redLoaded == true) { return(true); } } //Check if file is already in db, if so return true; if (fName.Contains("green") || fName.Contains("GREEN") || fName.Contains("Green")) { if (_greenLoaded == true) { return(true); } } int res = _dbCreator.parseInputFile(fName); if (res == 0 && (fName.Contains("red") || fName.Contains("RED") || fName.Contains("Red"))) { _redLoaded = true; _changeState = TrackChanged.Red; alertTrackChanged(); } if (res == 0 && (fName.Contains("green") || fName.Contains("GREEN") || fName.Contains("Green"))) { _greenLoaded = true; _changeState = TrackChanged.Green; alertTrackChanged(); } if (res == 0) { return(true); } else { return(false); } }
private void changeBeatmap(WorkingBeatmap newWorking) { // This method can potentially be triggered multiple times as it is eagerly fired in next() / prev() to ensure correct execution order // (changeBeatmap must be called before consumers receive the bindable changed event, which is not the case when the local beatmap bindable is updated directly). if (newWorking == current) { return; } var lastWorking = current; TrackChangeDirection direction = TrackChangeDirection.None; bool audioEquals = newWorking?.BeatmapInfo?.AudioEquals(current?.BeatmapInfo) == true; if (current != null) { if (audioEquals) { direction = TrackChangeDirection.None; } else if (queuedDirection.HasValue) { direction = queuedDirection.Value; queuedDirection = null; } else { // figure out the best direction based on order in playlist. int last = getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(current.BeatmapSetInfo)).Count(); int next = newWorking == null ? -1 : getBeatmapSets().AsEnumerable().TakeWhile(b => !b.Equals(newWorking.BeatmapSetInfo)).Count(); direction = last > next ? TrackChangeDirection.Prev : TrackChangeDirection.Next; } } current = newWorking; if (lastWorking == null || !lastWorking.TryTransferTrack(current)) { changeTrack(); } TrackChanged?.Invoke(current, direction); ResetTrackAdjustments(); queuedDirection = null; // this will be a noop if coming from the beatmapChanged event. // the exception is local operations like next/prev, where we want to complete loading the track before sending out a change. if (beatmap.Value != current && beatmap is Bindable <WorkingBeatmap> working) { working.Value = current; } }
private void changeBeatmap(WorkingBeatmap newMap) { if (newMap == current) { return; } var lastWorkingMap = current; TrackChangeDirection direction = TrackChangeDirection.None; bool audioEquals = newMap?.BeatmapInfo.AudioEquals(current?.BeatmapInfo) ?? false; if (current != null) { if (audioEquals) { direction = TrackChangeDirection.None; } else if (queuedDirection.HasValue) { direction = queuedDirection.Value; queuedDirection = null; } else { // figure out the best direction based on order in playlist. var last = BeatmapSets.TakeWhile(b => b.ID != current.BeatmapSetInfo?.ID).Count(); var next = newMap == null ? -1 : BeatmapSets.TakeWhile(b => b.ID != newMap.BeatmapSetInfo?.ID).Count(); direction = last > next ? TrackChangeDirection.Previous : TrackChangeDirection.Next; } } current = newMap; if (!audioEquals || CurrentTrack.IsDummyDevice) { changeTrack(); } else { // transfer still valid track to new working beatmap current.TransferTrack(lastWorkingMap.Track); } TrackChanged?.Invoke(current, direction); queuedDirection = null; if (beatmap.Value != current && beatmap is Bindable <WorkingBeatmap> working) { working.Value = current; } }
private void HandleTrackMessage(TrackDto track) { CurrentTrack = new Track { Artist = track.Artist, Title = track.Title, Album = track.Album, AlbumArtUrl = track.AlbumArt }; TrackChanged?.Invoke(this, new TrackChangedEventArgs(CurrentTrack)); }
protected override void OnTrackChanged(TrackChanged e) { if (e != null) { // Load the Album Art for the new Track LoadAlbumArt(e.NewTrack, m_albumArtResolution); SetTrackInfo(e.NewTrack.Title, e.NewTrack.Album, String.Join(", ", e.NewTrack.Artists.Select(x => x.Name))); UpdateSaveTrackBtn(); } }
private void DoTick() { _previousContext = _currentContext; try { _currentContext = _api.GetPlayback(); } catch (SpotifyWebApiException ex) { MessageBox.Show(ex.Message); Thread.Sleep(5000); return; } try { if (_currentContext == null) { return; } // Check volume change if (CompareContext(c => c.Device?.VolumePercent, out var oldVolume, out var newVolume)) { // Volume Changed VolumeChanged?.Invoke(this, new VolumeChangeEventArgs(oldVolume.GetValueOrDefault(), newVolume.GetValueOrDefault())); } if (CompareContext(c => c.Item, out var oldTrack, out var newTrack)) { // Track Changed TrackChanged?.Invoke(this, new TrackChangeEventArgs(oldTrack, newTrack)); } if (CompareContext(c => c.IsPlaying)) { // Playstate Changed PlayStateChanged?.Invoke(this, new PlayStateChangeEventArgs(_currentContext.IsPlaying)); } if (CompareContext(c => c.ProgressMs, out var oldProgressMs, out var newProgressMs)) { // Track Time Changed TrackTimeChanged?.Invoke(this, new TrackTimeChangeEventArgs(TimeSpan .FromMilliseconds(newProgressMs))); } Tick?.Invoke(this, new EventArgs()); } catch { } }
public void Refresh(PlaybackContext playback) { if (playback?.HasError() == false && playback.Item?.HasError() == false && playback.Item.Id != currentTrackId) { var trackInfo = TrackInfoFactory.Create(playback.Item); currentTrackId = playback.Item.Id; TrackChanged?.Invoke(trackInfo); } }
public void StartMusicInternal(QueueSong track) { if (track == null) { SkipToNext(); return; } _currentTrack = track; SetTrackUri(track); TrackChanged?.Invoke(this, _currentTrack.Id); }
public void AddRange(PlexTrack[] items) { lock (tracks) { foreach (var track in items) { tracks.Add(track); } } TrackChanged?.Invoke(this, new EventArgs()); }
/// <summary> /// A public method allowing external modules to update variable attributes of a block. /// The attributes that are changable include the health state (broken, failed, healthy). /// That's it. /// </summary> /// <param name="bToUpdate">The IBlock object</param> /// <returns></returns> public bool requestUpdateBlock(IBlock bToUpdate) { if (bToUpdate == null) { return(false); } if (bToUpdate.BlockID == 0) { return(false); } IBlock oldBlock = this.requestBlockInfo(bToUpdate.BlockID, bToUpdate.Line); if (oldBlock == null)//If it doesnt exist, return false { return(false); } //Check state between the oldBlock and the newBlock. If nothing changes, dont update, just return true if (oldBlock.State == bToUpdate.State) { return(true); } string updateString = _dbManager.createUpdate("BLOCK", bToUpdate); if (updateString == null) { return(false); } bool res = _dbManager.runUpdate(updateString); if (res) { //IF we're red if (bToUpdate.Line.Equals("Red", StringComparison.OrdinalIgnoreCase)) { _changeState = TrackChanged.Red; alertTrackChanged(); } else//We're green { _changeState = TrackChanged.Green; alertTrackChanged(); } } return(res); }
/// <summary> /// A constructor for the TrackModel module /// </summary> /// <param name="environment">Requires a reference to the surrounding environment object</param> public TrackModel(ISimulationEnvironment environment) { _redLoaded = false; _greenLoaded = false; _env = environment; _dbCreator = new DBCreator("",environment); _dbManager = new DBManager(_dbCreator.DBCon); _changeState = TrackChanged.None; IBlock redTemp = requestBlockInfo(1, "Red"); IBlock greenTemp = requestBlockInfo(1, "Green"); if (redTemp != null) { List<IBlock>[] tempBlockList=createBlockListArray(0); _dbCreator.populateTCs(tempBlockList, true); _changeState = TrackChanged.Red; _redLoaded = true; } if (greenTemp != null) { List<IBlock>[] tempBlockList = createBlockListArray(1); _dbCreator.populateTCs(tempBlockList, false); if (_changeState == TrackChanged.Red) _changeState = TrackChanged.Both; else _changeState = TrackChanged.Green; _greenLoaded = true; } if (_changeState != TrackChanged.None) { alertTrackChanged(); } //_environment.Tick+= }
/// <summary> /// A public method allowing modules to give input csv files to the TrackModel. This method /// takes the input files and parses them for insertion into the database. /// </summary> /// <param name="fName">The file name of the file to be parsed</param> /// <returns>A boolean corresponding to the success or failure of the file parsing and insertion</returns> public bool provideInputFile(string fName) { if (fName == null) return false; if (!fName.EndsWith(".csv")) { return false; } //Check if file is already in db, if so return true if (fName.Contains("red") || fName.Contains("RED") || fName.Contains("Red")) { if (_redLoaded == true) { return true; } } //Check if file is already in db, if so return true; if (fName.Contains("green") || fName.Contains("GREEN") || fName.Contains("Green")) { if (_greenLoaded == true) { return true; } } int res = _dbCreator.parseInputFile(fName); if ( res==0 && (fName.Contains("red") || fName.Contains("RED") || fName.Contains("Red"))) { _redLoaded = true; _changeState = TrackChanged.Red; alertTrackChanged(); } if (res==0 && (fName.Contains("green") || fName.Contains("GREEN") || fName.Contains("Green"))) { _greenLoaded = true; _changeState = TrackChanged.Green; alertTrackChanged(); } if (res == 0) return true; else return false; }
/// <summary> /// A public method allowing external modules to update variable attributes of a block. /// The attributes that are changable include the health state (broken, failed, healthy). /// That's it. /// </summary> /// <param name="bToUpdate">The IBlock object</param> /// <returns></returns> public bool requestUpdateBlock(IBlock bToUpdate) { if (bToUpdate == null) return false; if (bToUpdate.BlockID == 0) return false; IBlock oldBlock=this.requestBlockInfo(bToUpdate.BlockID, bToUpdate.Line); if (oldBlock == null)//If it doesnt exist, return false { return false; } //Check state between the oldBlock and the newBlock. If nothing changes, dont update, just return true if (oldBlock.State == bToUpdate.State) { return true; } string updateString = _dbManager.createUpdate("BLOCK", bToUpdate); if (updateString == null) return false; bool res = _dbManager.runUpdate(updateString); if (res) { //IF we're red if (bToUpdate.Line.Equals("Red", StringComparison.OrdinalIgnoreCase)) { _changeState = TrackChanged.Red; alertTrackChanged(); } else//We're green { _changeState = TrackChanged.Green; alertTrackChanged(); } } return res; }
/// <summary> /// This public method is used to allow other modules to request a change in switch state for /// a block. /// </summary> /// <param name="bToUpdate"> An IBlock object with the updated switch state.</param> /// <returns>A boolean object representing the success or failure of the database update</returns> public bool requestUpdateSwitch(IBlock bToUpdate) { if (bToUpdate == null) return false; if (bToUpdate.hasSwitch() == false) return false; string updateString = _dbManager.createUpdate("SWITCH", bToUpdate); if (updateString == null) return false; bool res = _dbManager.runUpdate(updateString); //Update our "TRACK CHANGED" flag if necessary if (res) { //IF we're red if (bToUpdate.Line.Equals("Red", StringComparison.OrdinalIgnoreCase)) { _changeState = TrackChanged.Red; alertTrackChanged(); } else//We're green { _changeState = TrackChanged.Green; alertTrackChanged(); } } return res; }