void PopulateCollectionView (string whichAlbum) { if (string.IsNullOrEmpty (whichAlbum)) return; var tableData = new NSDataAsset (whichAlbum); try { var jsonString = NSString.FromData (tableData.Data, NSStringEncoding.UTF8); previewDetails = JsonConvert.DeserializeObject<List<PreviewDetail>> (jsonString); CustomTableView.ReloadData (); } catch (Exception e) { Console.WriteLine ("Error occurred: {0}", e.Message); } }
void PopulateCollectionView(string whichAlbum) { if (string.IsNullOrEmpty(whichAlbum)) { return; } var tableData = new NSDataAsset(whichAlbum); try { var jsonString = NSString.FromData(tableData.Data, NSStringEncoding.UTF8); previewDetails = JsonConvert.DeserializeObject <List <PreviewDetail> > (jsonString); CustomTableView.ReloadData(); } catch (Exception e) { Console.WriteLine("Error occurred: {0}", e.Message); } }
void LoadPrefetchResources() { request = new NSBundleResourceRequest(new[] { "prefetch" }); request.BeginAccessingResources(error => { NSOperationQueue.MainQueue.AddOperation(() => { if (error != null) { Console.WriteLine("Error occurred: {0}", error.LocalizedDescription); return; } var dataAsset = new NSDataAsset("TestDataAsset"); if (dataAsset == null) { Throw("Failed to load pre-fetched resource TestDataAsset"); } LoadOdrsResources(); }); }); }
private async Task <DataResolverResult> ResolveFromAssetCatalogAsync(string fileName, string identifier, TaskParameter parameters, CancellationToken token) { #if __IOS__ || __TVOS__ if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { return(null); } #endif NSDataAsset asset = null; try { await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => asset = new NSDataAsset(identifier, NSBundle.MainBundle)).ConfigureAwait(false); } catch { } if (asset == null && fileName != identifier) { try { await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => asset = new NSDataAsset(fileName, NSBundle.MainBundle)).ConfigureAwait(false); } catch { } } if (asset != null) { token.ThrowIfCancellationRequested(); var stream = asset.Data?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new DataResolverResult(stream, LoadingResult.CompiledResource, imageInformation)); } return(null); }
public void Prepare(string assetName, HandlePrepare prepareHandler) { if (mAudioPlayer != null) { mAudioPlayer.Stop(); mAudioPlayer.Dispose(); } bool result = false; int extStartDotIndex = assetName.LastIndexOf('.'); if (extStartDotIndex > 0) { string fileName = assetName.Substring(0, extStartDotIndex); string extName = assetName.Substring(extStartDotIndex); NSDataAsset assetData = new NSDataAsset(fileName); NSError error = null; if (assetData != null) { AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback); AVAudioSession.SharedInstance().SetActive(true); mAudioPlayer = new AVAudioPlayer(assetData.Data, extName, out error); SetLooping(mLoop); SetVolume(mLeftVolume, mRightVolume); } result = error == null; if (result) { result = mAudioPlayer.PrepareToPlay(); } } prepareHandler?.Invoke(assetName, result); }
public virtual async Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token) { NSBundle bundle = null; var filename = Path.GetFileNameWithoutExtension(identifier); var tmpPath = Path.GetDirectoryName(identifier).Trim('/'); var filenamePath = string.IsNullOrWhiteSpace(tmpPath) ? null : tmpPath + "/"; foreach (var fileType in fileTypes) { string file = null; var extension = Path.HasExtension(identifier) ? Path.GetExtension(identifier) : string.IsNullOrWhiteSpace(fileType) ? string.Empty : "." + fileType; token.ThrowIfCancellationRequested(); int scale = (int)ScaleHelper.Scale; if (scale > 1) { while (scale > 1) { token.ThrowIfCancellationRequested(); var tmpFile = string.Format("{0}@{1}x{2}", filename, scale, extension); bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = string.IsNullOrWhiteSpace(filenamePath) ? bu.PathForResource(tmpFile, null) : bu.PathForResource(tmpFile, null, filenamePath); return(!string.IsNullOrWhiteSpace(path)); }); if (bundle != null) { file = tmpFile; break; } scale--; } } token.ThrowIfCancellationRequested(); if (file == null) { var tmpFile = string.Format(filename + extension); file = tmpFile; bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = string.IsNullOrWhiteSpace(filenamePath) ? bu.PathForResource(tmpFile, null) : bu.PathForResource(tmpFile, null, filenamePath); return(!string.IsNullOrWhiteSpace(path)); }); } token.ThrowIfCancellationRequested(); if (bundle != null) { string path = !string.IsNullOrEmpty(filenamePath) ? bundle.PathForResource(file, null, filenamePath) : bundle.PathForResource(file, null); var stream = FileStore.GetInputStream(path, true); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(path); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } token.ThrowIfCancellationRequested(); if (string.IsNullOrEmpty(fileType)) { //Asset catalog NSDataAsset asset = null; try { await MainThreadDispatcher.Instance.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false); } catch (Exception) { } if (asset != null) { token.ThrowIfCancellationRequested(); var stream = asset.Data?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } NSImage image = null; try { await MainThreadDispatcher.Instance.PostAsync(() => image = NSImage.ImageNamed(filename)).ConfigureAwait(false); } catch (Exception) { } if (image != null) { token.ThrowIfCancellationRequested(); var imageRep = new NSBitmapImageRep(image.AsTiff()); var stream = imageRep.RepresentationUsingTypeProperties(NSBitmapImageFileType.Png) .AsStream(); //var stream = image.AsPNG()?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } } } throw new FileNotFoundException(identifier); }
public virtual async Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token) { NSBundle bundle = null; var filename = Path.GetFileNameWithoutExtension(identifier); var tmpPath = Path.GetDirectoryName(identifier).Trim('/'); var filenamePath = string.IsNullOrWhiteSpace(tmpPath) ? null : tmpPath + "/"; foreach (var fileType in fileTypes) { string file = null; var extension = Path.HasExtension(identifier) ? Path.GetExtension(identifier) : string.IsNullOrWhiteSpace(fileType) ? string.Empty : "." + fileType; token.ThrowIfCancellationRequested(); int scale = (int)ScaleHelper.Scale; if (scale > 1) { while (scale > 1) { token.ThrowIfCancellationRequested(); var tmpFile = string.Format("{0}@{1}x{2}", filename, scale, extension); bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = string.IsNullOrWhiteSpace(filenamePath) ? bu.PathForResource(tmpFile, null) : bu.PathForResource(tmpFile, null, filenamePath); return(!string.IsNullOrWhiteSpace(path)); }); if (bundle != null) { file = tmpFile; break; } scale--; } } token.ThrowIfCancellationRequested(); if (file == null) { var tmpFile = string.Format(filename + extension); file = tmpFile; bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = string.IsNullOrWhiteSpace(filenamePath) ? bu.PathForResource(tmpFile, null) : bu.PathForResource(tmpFile, null, filenamePath); return(!string.IsNullOrWhiteSpace(path)); }); } token.ThrowIfCancellationRequested(); if (bundle != null) { string path = !string.IsNullOrEmpty(filenamePath) ? bundle.PathForResource(file, null, filenamePath) : bundle.PathForResource(file, null); var stream = FileStore.GetInputStream(path, true); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(path); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } token.ThrowIfCancellationRequested(); if (string.IsNullOrEmpty(fileType)) { //Asset catalog bool tryAssetsCatalog = true; #if __IOS__ if (!UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { tryAssetsCatalog = false; } #endif if (tryAssetsCatalog) { NSDataAsset asset = null; try { await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false); } catch (Exception) { } if (asset != null) { token.ThrowIfCancellationRequested(); var stream = asset.Data?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } } PImage image = null; try { #if __IOS__ await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = PImage.FromBundle(filename)).ConfigureAwait(false); #elif __MACOS__ await ImageService.Instance.Config.MainThreadDispatcher.PostAsync(() => image = NSImage.ImageNamed(filename)).ConfigureAwait(false); #endif } catch (Exception) { } if (image != null) { token.ThrowIfCancellationRequested(); var stream = image.AsPngStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } } } throw new FileNotFoundException(identifier); }
public virtual async Task <Tuple <Stream, LoadingResult, ImageInformation> > Resolve(string identifier, TaskParameter parameters, CancellationToken token) { NSBundle bundle = null; string file = null; var filename = Path.GetFileNameWithoutExtension(identifier); var extension = Path.GetExtension(identifier); const string pattern = "{0}@{1}x{2}"; foreach (var fileType in fileTypes) { token.ThrowIfCancellationRequested(); int scale = (int)ScaleHelper.Scale; if (scale > 1) { while (scale > 1) { token.ThrowIfCancellationRequested(); var tmpFile = string.Format(pattern, filename, scale, extension); bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = bu.PathForResource(tmpFile, fileType); return(!string.IsNullOrWhiteSpace(path)); }); if (bundle != null) { file = tmpFile; break; } scale--; } } token.ThrowIfCancellationRequested(); if (file == null) { file = identifier; bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = bu.PathForResource(file, fileType); return(!string.IsNullOrWhiteSpace(path)); }); } token.ThrowIfCancellationRequested(); if (bundle != null) { var path = bundle.PathForResource(file, fileType); var stream = FileStore.GetInputStream(path, true); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(path); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } } //Asset catalog token.ThrowIfCancellationRequested(); if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { NSDataAsset asset = null; try { await MainThreadDispatcher.Instance.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false); } catch (Exception) { } if (asset != null) { token.ThrowIfCancellationRequested(); var stream = asset.Data?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } } else if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { UIImage image = null; try { await MainThreadDispatcher.Instance.PostAsync(() => image = UIImage.FromBundle(filename)).ConfigureAwait(false); } catch (Exception) { } if (image != null) { token.ThrowIfCancellationRequested(); var stream = image.AsPNG()?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return(new Tuple <Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation)); } } throw new FileNotFoundException(identifier); }
public virtual async Task<Tuple<Stream, LoadingResult, ImageInformation>> Resolve(string identifier, TaskParameter parameters, CancellationToken token) { NSBundle bundle = null; string file = null; var filename = Path.GetFileNameWithoutExtension(identifier); var extension = Path.GetExtension(identifier); const string pattern = "{0}@{1}x{2}"; foreach (var fileType in fileTypes) { token.ThrowIfCancellationRequested(); int scale = (int)ScaleHelper.Scale; if (scale > 1) { while (scale > 1) { token.ThrowIfCancellationRequested(); var tmpFile = string.Format(pattern, filename, scale, extension); bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = bu.PathForResource(tmpFile, fileType); return !string.IsNullOrWhiteSpace(path); }); if (bundle != null) { file = tmpFile; break; } scale--; } } token.ThrowIfCancellationRequested(); if (file == null) { file = identifier; bundle = NSBundle._AllBundles.FirstOrDefault(bu => { var path = bu.PathForResource(file, fileType); return !string.IsNullOrWhiteSpace(path); }); } token.ThrowIfCancellationRequested(); if (bundle != null) { var path = bundle.PathForResource(file, fileType); var stream = FileStore.GetInputStream(path, true); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(path); return new Tuple<Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation); } } //Asset catalog token.ThrowIfCancellationRequested(); if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { NSDataAsset asset = null; try { await MainThreadDispatcher.Instance.PostAsync(() => asset = new NSDataAsset(filename)).ConfigureAwait(false); } catch (Exception) { } if (asset != null) { token.ThrowIfCancellationRequested(); var stream = asset.Data?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return new Tuple<Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation); } } else if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { UIImage image = null; try { await MainThreadDispatcher.Instance.PostAsync(() => image = UIImage.FromBundle(filename)).ConfigureAwait(false); } catch (Exception) { } if (image != null) { token.ThrowIfCancellationRequested(); var stream = image.AsPNG()?.AsStream(); var imageInformation = new ImageInformation(); imageInformation.SetPath(identifier); imageInformation.SetFilePath(null); return new Tuple<Stream, LoadingResult, ImageInformation>( stream, LoadingResult.CompiledResource, imageInformation); } } throw new FileNotFoundException(identifier); }
void LoadPrefetchResources() { request = new NSBundleResourceRequest(new[] { "prefetch" }); request.BeginAccessingResources(error => { NSOperationQueue.MainQueue.AddOperation(() => { if (error != null) { Console.WriteLine("Error occurred: {0}", error.LocalizedDescription); return; } var dataAsset = new NSDataAsset("TestDataAsset"); if (dataAsset == null) Throw("Failed to load pre-fetched resource TestDataAsset"); LoadOdrsResources (); }); }); }