public void Handle(PlayRequestMessage message) { if (currentlyPlaying == message.Media) { MediaPlayerState = PlayerState.Playing; return; } if (currentlyPlaying != null) { currentlyPlaying.IsDeletedChanged -= CurrentlyPlayingDeleted; currentlyPlaying.MediaPosition = SliderPosition; mediaItemPersister.Save(currentlyPlaying); log.Info("Saved previous media position: {0}", currentlyPlaying.Name); } MediaPlayerState = PlayerState.Stopped; currentlyPlaying = message.Media; NotifyOfPropertyChange(() => CurrentlyPlaying); NotifyOfPropertyChange(() => MediaStream); NotifyOfPropertyChange(() => CanPlayPause); NotifyOfPropertyChange(() => CanStop); if (currentlyPlaying != null) { currentlyPlaying.IsDeletedChanged += CurrentlyPlayingDeleted; MediaPlayerState = PlayerState.Playing; } else { MediaPositionText = ""; MediaPositionMax = 0; } log.Info("Started playing item: {0}", currentlyPlaying != null ? currentlyPlaying.Name : "(Nothing)"); }
public MediaItem AddNewMediaItem(string name, Uri originalUri) { var newMediaItem = new MediaItem { Name = name, IsAvailable = false }; MediaItems.Add(newMediaItem); log.Info("Adding item {0} (url: {1}) to library", name, originalUri); var client = new WebClient(); client.OpenReadCompleted += (s, e) => { log.Info("Item {0} (url: {1}) download complete.", name, originalUri); newMediaItem.DataStream = () => e.Result; newMediaItem.IsAvailable = true; mediaItemPersister.Save(newMediaItem); mediaItems.RaiseCollectionChanged(); }; client.DownloadProgressChanged += (s, e) => { newMediaItem.DownloadProgress = e.ProgressPercentage; }; client.OpenReadAsync(originalUri); return newMediaItem; }