/// <summary>
        /// Clicking on the save button saves the photo in DataContext.ImageStream to media library
        /// camera roll. Once image has been saved, the application will navigate back to the main page.
        /// </summary>
        private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Reposition ImageStream to beginning, because it has been read already in the OnNavigatedTo method.
                _dataContext.ImageStream.Position = 0;

                MediaLibrary library = new MediaLibrary();
                library.SavePictureToCameraRoll("CameraExplorer_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg", _dataContext.ImageStream);

                // There should be no temporary file left behind
                using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var files = isolatedStorage.GetFileNames("CameraExplorer_*.jpg");
                    foreach (string file in files)
                    {
                        isolatedStorage.DeleteFile(file);
                        //System.Diagnostics.Debug.WriteLine("Temp file deleted: " + file);
                    }
                }

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Saving picture to camera roll failed: " + ex.HResult.ToString("x8") + " - " + ex.Message);
            }

            NavigationService.GoBack();
        }
 public void PlayAlbumArtist(MediaLibrary.AlbumArtist artist, bool enqueue,
     Action<MediaState, object, Exception> callback, object state)
 {
     lock (_syncLock)
     {
         Tuple<Action<MediaState, object, Exception>, object> innerState = new Tuple<Action<MediaState, object, Exception>, object>(callback, state);
         QueueRequest(new PlayAlbumArtistDelegate(PlaybackServiceClient.PlayAlbumArtistAsync), new PlayAlbumArtistRequest(artist.ConvertToArtist(), enqueue), innerState);
     }
 }
 public void GetAlbumArtByTrackAsync(MediaLibrary.Track track,
     Action<MediaLibrary.Track, byte[], object, Exception> callback, object state)
 {
     lock (_syncLock)
     {
         Tuple<Action<MediaLibrary.Track, byte[], object, Exception>, object, MediaLibrary.Track> innerState =
             new Tuple<Action<MediaLibrary.Track, byte[], object, Exception>, object, MediaLibrary.Track>(callback, state, track);
         QueueLowPriorityRequest(new GetAlbumArtByTrackDelegate(LibraryServiceClient.GetAlbumArtByTrackAsync), new GetAlbumArtByTrackRequest(track), innerState);
     }
 }
 public void GetAlbumArtByAlbumAsync(MediaLibrary.Album album,
     Action<MediaLibrary.Album, byte[], object, Exception> callback, object state)
 {
     lock (_syncLock)
     {
         Tuple<Action<MediaLibrary.Album, byte[], object, Exception>, object, MediaLibrary.Album> innerState =
             new Tuple<Action<MediaLibrary.Album, byte[], object, Exception>, object, MediaLibrary.Album>(callback, state, album);
         QueueLowPriorityRequest(new GetAlbumArtByAlbumDelegate(LibraryServiceClient.GetAlbumArtByAlbumAsync), new GetAlbumArtByAlbumRequest(album), innerState);
     }
 }
Esempio n. 5
0
        public static bool EqualsTrack(this MediaLibrary.Track track, MediaLibrary.Track track2)
        {
            if (track == null && track2 == null)
            {
                return true;
            }
            else if (track == null || track2 == null)
            {
                return false;
            }

            return (track.FilePath == track2.FilePath);
        }
Esempio n. 6
0
 public void CancelRequest(MediaLibrary.Album album)
 {
     if (_queuedRequests.Contains(album))
     {
         lock (_requestLock)
         {
             if (_queuedRequests.Contains(album))
             {
                 Debug.WriteLine("Cancelled request for {0}", album.ID);
                 _queuedRequests.Remove(album);
             }
         }
     }
 }
 public void PlayTrack(MediaLibrary.Track track,
     Action<MediaState, object, Exception> callback, object state)
 {
     lock (_syncLock)
     {
         Tuple<Action<MediaState, object, Exception>, object> innerState = new Tuple<Action<MediaState, object, Exception>, object>(callback, state);
         QueueRequest(new PlayTrackDelegate(PlaybackServiceClient.PlayTrackAsync), new PlayTrackRequest(track.ConvertToTrack()), innerState);
     }
 }
Esempio n. 8
0
 public AlbumViewModel(MediaLibrary.Album album)
 {
     Album = album;
 }
Esempio n. 9
0
        private void SetAlbumArtAge(MediaLibrary.Album album)
        {
            lock (_syncLock)
            {
                bool isCurrentArtYoungest = false;
                if (_albumArtAge.ContainsKey(album.ID))
                {
                    isCurrentArtYoungest = (_albumArtAge[album.ID] == 0);
                    if (!isCurrentArtYoungest)
                    {
                        _albumArtAge[album.ID] = 0;
                    }
                }
                else
                {
                    _albumArtAge.Add(album.ID, 0);
                }

                List<string> keys = new List<string>();
                if (!isCurrentArtYoungest)
                {
                    foreach (string key in _albumArtAge.Keys)
                    {
                        keys.Add(key);

                    }

                    foreach (string key in keys)
                    {
                        if (string.Equals(key, album.ID))
                        {
                            _albumArtAge[key] = 0;
                        }
                        else
                        {
                            _albumArtAge[key]++;
                        }
                    }
                }
            }

            TrimExcessAlbumArt();
        }
Esempio n. 10
0
 private void FireAlbumArtDownloaded(MediaLibrary.Album album, BitmapImage albumArt)
 {
     if (_albumArtDownloaded != null)
     {
         _albumArtDownloaded(this, new EventArgs<MediaLibrary.Album, BitmapImage>(album, albumArt));
     }
 }
Esempio n. 11
0
        private void DownloadAlbumArt(MediaLibrary.Album album)
        {
            App.GetService<IRequestService>().GetAlbumArtByAlbumAsync(album,
                    (innerAlbum, imageData, state, error) =>
                    {
                        BitmapImage albumArt = null;
                        if (error == null && imageData != null && imageData.Length > 0)
                        {
                            albumArt = new BitmapImage();
                            if (imageData != null)
                            {
                                try
                                {
                                    using (MemoryStream artStream = new MemoryStream(imageData))
                                    {
                                        albumArt.SetSource(artStream);
                                    }
                                }
                                catch (Exception)
                                {
                                    albumArt = null;
                                }
                            }
                        }

                        lock (_syncLock)
                        {
                            if (_albumArtAge.ContainsKey(innerAlbum.ID))
                            {
                                if (_albumArtCache.ContainsKey(innerAlbum.ID))
                                {
                                    _albumArtCache[innerAlbum.ID] = albumArt;
                                }
                                else
                                {
                                    _albumArtCache.Add(innerAlbum.ID, albumArt);
                                }
                            }

                            FireAlbumArtDownloaded(innerAlbum, _albumArtCache[innerAlbum.ID]);
                        }

                        // Now, start the timer up again
                        StartTimer(0, 0);
                    }, null);
        }
Esempio n. 12
0
        public void GetAlbumArtAsync(MediaLibrary.Album album)
        {
            if (string.IsNullOrEmpty(album.ID))
            {
                return;
            }

            SetAlbumArtAge(album);

            if (_albumArtCache.ContainsKey(album.ID))
            {
                FireAlbumArtDownloaded(album, _albumArtCache[album.ID]);
            }
            else
            {
                lock (_requestLock)
                {
                    _queuedRequests.Add(album);
                    StartTimer(0, 300);
                }
            }
        }
 private void LibraryServiceClient_PingCompleted(object sender, MediaLibrary.PingCompletedEventArgs e)
 {
     if (RequestCompleted(e.Error))
     {
         Tuple<Action<object, Exception>, object> innerState = (Tuple<Action<object, Exception>, object>)e.UserState;
         if (innerState.Item1 != null)
         {
             innerState.Item1.Invoke(innerState.Item2, e.Error);
         }
     }
 }
 public void GetTracksAsync(MediaLibrary.Album album,
     Action<List<MediaLibrary.Track>, object, Exception> callback, object state)
 {
     lock (_syncLock)
     {
         Tuple<Action<List<MediaLibrary.Track>, object, Exception>, object> innerState =
             new Tuple<Action<List<MediaLibrary.Track>, object, Exception>, object>(callback, state);
         QueueRequest(new GetTracksDelegate(LibraryServiceClient.GetTracksAsync), new GetTracksRequest(album), innerState);
     }
 }
 public void GetAlbumsByArtistAsync(MediaLibrary.Artist artist, Action<List<MediaLibrary.Album>, object, Exception> callback, object state)
 {
     lock (_syncLock)
     {
         Tuple<Action<List<MediaLibrary.Album>, object, Exception>, object> innerState =
             new Tuple<Action<List<MediaLibrary.Album>, object, Exception>, object>(callback, state);
         QueueRequest(new GetAlbumsByArtistDelegate(LibraryServiceClient.GetAlbumsByArtistAsync), new GetAlbumsByArtistRequest(artist), innerState);
     }
 }
Esempio n. 16
0
 public AlbumClickedArgs(MediaLibrary.Album album)
 {
     Album = album;
 }