public static void OpenDocumentCommon(TLMessage message, IStateService stateService, IDocumentFileManager documentFileManager, System.Action openGifCallback) #endif { var mediaDocument = message.Media as TLMessageMediaDocument; if (mediaDocument != null) { var document = mediaDocument.Document as TLDocument; if (document == null) { return; } var documentLocalFileName = document.GetFileName(); var store = IsolatedStorageFile.GetUserStoreForApplication(); #if WP81 var documentFile = mediaDocument.File ?? await GetStorageFile(mediaDocument); #endif if (!store.FileExists(documentLocalFileName) #if WP81 && documentFile == null #endif ) { mediaDocument.IsCanceled = false; mediaDocument.DownloadingProgress = mediaDocument.LastProgress > 0.0 ? mediaDocument.LastProgress : 0.001; //_downloadVideoStopwatch = Stopwatch.StartNew(); documentFileManager.DownloadFileAsync( document.FileName, document.DCId, document.ToInputFileLocation(), message, document.Size, progress => { if (progress > 0.0) { mediaDocument.DownloadingProgress = progress; } }); } else { if (documentLocalFileName.EndsWith(".gif") || string.Equals(document.MimeType.ToString(), "image/gif", StringComparison.OrdinalIgnoreCase)) { openGifCallback.SafeInvoke(); return; } if (documentLocalFileName.EndsWith(".mp3") || string.Equals(document.MimeType.ToString(), "audio/mpeg", StringComparison.OrdinalIgnoreCase)) { var url = new Uri(documentLocalFileName, UriKind.Relative); var title = document.FileName.ToString(); var performer = "Unknown Artist"; var readId3Tags = true; #if WP81 try { var storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync(documentLocalFileName); var audioProperties = await storageFile.Properties.GetMusicPropertiesAsync(); title = audioProperties.Title; performer = audioProperties.Artist; readId3Tags = false; } catch (Exception ex) { } #endif #if WP81 if (documentFile == null) { try { documentFile = await ApplicationData.Current.LocalFolder.GetFileAsync(documentLocalFileName); } catch (Exception ex) { Execute.ShowDebugMessage("LocalFolder.GetFileAsync docLocal exception \n" + ex); } } Launcher.LaunchFileAsync(documentFile); return; #elif WP8 var file = await ApplicationData.Current.LocalFolder.GetFileAsync(documentLocalFileName); Launcher.LaunchFileAsync(file); return; #endif //if (readId3Tags) //{ // if (store.FileExists(documentLocalFileName)) // { // using (var file = store.OpenFile(documentLocalFileName, FileMode.Open, FileAccess.Read)) // { // var mp3Stream = new Mp3Stream(file); // if (mp3Stream.HasTags) // { // var tag = mp3Stream.GetTag(Id3TagFamily.FileStartTag); // title = tag.Title; // performer = tag.Artists; // } // } // } //} //var track = BackgroundAudioPlayer.Instance.Track; //if (track == null || track.Source != url) //{ // BackgroundAudioPlayer.Instance.Track = new AudioTrack(url, title, performer, null, null); //} //BackgroundAudioPlayer.Instance.Play(); return; } else { #if WP81 if (documentFile == null) { try { documentFile = await ApplicationData.Current.LocalFolder.GetFileAsync(documentLocalFileName); } catch (Exception ex) { Execute.ShowDebugMessage("LocalFolder.GetFileAsync docLocal exception \n" + ex); } } Launcher.LaunchFileAsync(documentFile); return; #elif WP8 var file = await ApplicationData.Current.LocalFolder.GetFileAsync(documentLocalFileName); Launcher.LaunchFileAsync(file); return; #endif } } return; } }
public static async void OpenDocumentCommon(TLMessage message, IStateService stateService, IDocumentFileManager documentFileManager, System.Action openGifCallback)