Here is my code........
public MediaPlaybackItem GetMediaPlaybackItemFromPath(string path)
{
//StorageFile file = await StorageFile.GetFileFromPathAsync(path);
var source = MediaSource.CreateFromUri(new Uri(path));
return new MediaPlaybackItem(source);
}
If I use this method I cannot play music. But if I try this I can play music.
public async Task<MediaPlaybackItem> GetMediaPlaybackItemFromPathAsync(string path)
{
StorageFile file = await StorageFile.GetFileFromPathAsync(path);
var source = MediaSource.CreateFromStorageFile(file);
return new MediaPlaybackItem(source);
}
Whats the problem with this? I am using mediaplaybacklist for MediaPlayer.Source . How can I get proper MediaSource using my first method? Help me please.
You could not pass file path parameter to CreateFromUri directly. In general, the Uri parameter is http protocol address such as http://www.testvideo.com/forkvideo/test.mp4. But we could pass the file path with uwp file access uri scheme.
For example:
Media file stored in the installation folder.
ms-appx:///
Local folder.
ms-appdata:///local/
Temporary folder.
ms-appdata:///temp/
For more you could refer this document.
Related
I have function app read the file from data lake and do some processing of the file content. If it failed it move the file to the "Error" folder. I tried this but was unsuccessful. Solution I tried SO-solution
public static async Task<DataLakeFileClient> MoveDirectory(string file)
{
DataLakeServiceClient serviceClient = await GetDataLakeClient();
DataLakeFileSystemClient filesystemClient =
serviceClient.GetFileSystemClient(<CONTAINER>);
DataLakeFileClient fileClient =
filesystemClient.GetFileClient("Provision/" + file);
return await fileClient.RenameAsync("Provision/Error/" + file);
}
Cause a 404 SourcePathNotFound.
Any tips or advice how I can move files from one directory to another?
After making a few changes we could able to get this work. While using GetFileClient for the required file you need to use DataLakeFileSystemClient instead of DataLakeServiceClient. Below is the code that worked for me.
DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient("<CONNECTION STRING>");
DataLakeFileSystemClient dataLakeFileSystemClient = dataLakeServiceClient.GetFileSystemClient("<CONTAINER>");
DataLakeFileClient sourceDataLakeFileClient = dataLakeFileSystemClient.GetFileClient("provision/<FILENAME>");
return await sourceDataLakeFileClient.RenameAsync("provision/Error/<FILENAME>");
RESULTS:
Before execution
After execution
I want to get a thumbnail image of all photo files in a specific folder.
(Example: My C: \ Mypic)
I found another way to get a single thumbnail image, but this isn't exactly what i want
async private Task<BitmapImage> Thumbnail_call()
{
var files = await KnownFolders.PicturesLibrary.GetFilesAsync();
var thumb = await files[0].GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView);
var bitm = new BitmapImage();
bitm.SetSource(thumb);
return bitm;
}
I think that i have to use foreach sentence
Can you give me a solution to this problem?
In UWP app, you can access certain file system locations by default. Apps can also access additional locations through the file or folder picker, or by declaring capabilities. See File access permissions for more details about accessing the folders or files.
After you get the specific folders, you can get all thumbnails in it as the following code.
async private Task<List<BitmapImage>> GetThumbnails(StorageFolder folder)
{
List<BitmapImage> BitmapImageList = new List<BitmapImage>();
var files = await folder.GetFilesAsync();
foreach (var file in files)
{
var thumb = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.PicturesView);
var bitmap = new BitmapImage();
bitmap.SetSource(thumb);
BitmapImageList.Add(bitmap);
}
return BitmapImageList;
}
I'm having trouble retrieving videos that I have recorded from my app on my iPhone.
The purpose of this is to upload this recorded video to Amazon Web Service's cloud (store it in a bucket).
However I seem to only be have directory access capabilities instead of the actual files. I don't know if this is a permissions issue or if there's a specific class that allows me to retrieve recorded videos.
This snippet of code saves the video:
var options = new PHAssetResourceCreationOptions {};
var changeRequest = PHAssetCreationRequest.CreationRequestForAsset ();
changeRequest.AddResource (PHAssetResourceType.Video, outputFileUrl, options);
The path from the outputFileUrl, which saves to the iPhone's temp folder, is how I was going about trying to retrieve the file to upload but to no success.
Can someone help me with this?
I have an toggle Record Event that gets the file like this:
// Start recording to a temporary file.
MovieFileOutput.StartRecordingToOutputFile (new NSUrl(GetTmpFilePath ("mov"), false), this);
This is the definition for GetTmpFilePath():
static string GetTmpFilePath (string extension)
{
// Start recording to a temporary file.
string outputFileName = NSProcessInfo.ProcessInfo.GloballyUniqueString;
string tmpDir = Path.GetTempPath();
string outputFilePath = Path.Combine (tmpDir, outputFileName);
return Path.ChangeExtension (outputFilePath, extension);
}
outputFileUrl is a NSUrl and is the result of this, it is a parameter to the method that uses this in the "AddResource" above.
I am trying to start an intent in order to open an image file, I download from the internet.
The image file I can download to the internal storage of the app, but I can't copy it to the public /Documents directory on my Android device, in order to start the intent.
This is how I copy the file
var bytes = System.IO.File.ReadAllBytes (privatePath);
Java.IO.File docFolder = new Java.IO.File (global::Android.OS.Environment.ExternalStorageDirectory + "/MyAppCache");
if (!docFolder.Exists ()) docFolder.Mkdir ();
Java.IO.File file = new Java.IO.File (docFolder.AbsolutePath, "cache.jpg");
file.CreateNewFile();
Java.IO.FileOutputStream fOut = new Java.IO.FileOutputStream (file);
fOut.Write (bytes);
fOut.Close ();
return file.AbsolutePath;
the returned path I use for
global::Android.Net.Uri uri = global::Android.Net.Uri.Parse(FilePublisher.CopyToPublic());
StartActivity (new Intent (Intent.ActionView, uri));
The result I get is
No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/emulated/0/MyAppCache/cache.jpg }
I checked the /storage folder on my device and there isn't even the MyAppCache folder in it.
What is wrong here?
The URI you are passing in the Intent doesn't contain the scheme. You can see this from the error:
No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/emulated/0/MyAppCache/cache.jpg }
The "dat=" needs to start with file:///.
I am trying to load a pdf file from a folder in my win8 app. It is in the test folder. I try
StorageFile file = StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Test/example.pdf"));
That gives me a file not found. However, if I change the extension of example.pdf to jpg, then change the code to look for example.jpg, it does work properly. What is going on?
Try this:
public async Task<StorageFile> GetFileAsync(string directory, string fileName)
{
string filePath = BuildPath(directory, fileName);
string directoryName = Path.GetDirectoryName(filePath);
StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(directoryName);
StorageFile storageFile = await storageFolder.GetFileAsync(fileName);
return storageFile;
}
public string BuildPath(string directoryPath, string fileName)
{
string directory = Path.Combine(Package.Current.InstalledLocation.Path, directoryPath);
return Path.Combine(directory, fileName);
}
From your client, pass-in the directory (relative to the project) path of the file and then supply the file name for the second parameter.
In addition, it's probably good that you just create a library to manage various file operations.