I want to play a local video inside my Xamarin.Android app but when I set the uri the Visual Studio output tells me that the app can't read the video.
My video is located in the "files" folder of my app:
com.myapp.myap
cache/
files/
videos_files/
video.mp4
Here's my code:
var videoview = this.FindViewById<VideoView>(Resource.Id.videoView);
var uri = Android.Net.Uri.Parse("android.resource://com.myapp.com/files/videos_files/video.mp4");
videoView.SetVideoURI(uri);
Using the android.resource://blahblahblah format is only used when your files are included in your Resources folder with Build Action AndroidResource.
If you want this, then you can move your video file into YourApp/Resources/Raw.
Then set up your path:
string videoPath = $"android.resource://com.myapp.com/{Resource.Raw.video}";
videoView.SetVideoPath(videoPath);
Related
Hi I am trying to connect my c# mobile app (Android, iOS) to the google cloud firestore database. The problem I'm running into is that when I'm trying to set up my environment variable, my application can't seem to find the path to the json file which contains the service account key, even though I added the json file into the Android Assets folder, as well as the main project. This is my code:
string path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "dbfile.json");
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
FirestoreDb newDB = FirestoreDb.Create("projectKey");
But it gives me this error:
System.InvalidOperationException
Message=Error reading credential file from location /data/user/0/.../files/dbfile.json: Could not find file "/data/user/0/.../files/dbfile.json"
Please check the value of the Environment Variable GOOGLE_APPLICATION_CREDENTIALS
Does anyone know how to properly get the file path in a cross platform mobile app?
If you add the file into Android Assets folder,you should read it like below:
string content;
AssetManager assets = this.Assets;
using (StreamReader sr = new StreamReader (assets.Open ("your file")))
{
content = sr.ReadToEnd ();
}
You could refer to Reading Assets.
I have 2 projects in my solution, my API project and my project that I send info to API.
this its in my controller on project that sent to API:
pic = Path.GetFileName(file.FileName);//image name
path = Path.GetFullPath(Path.Combine(Server.MapPath("~"), #"WebApi1/Employee/"));//path in my project api
path2 = Path.Combine(path, Path.GetFileName(pic));//try combine path folder in api + image name
file.SaveAs(path2);//try safe image in folder api
using (MemoryStream ms = new MemoryStream())
{
file.InputStream.CopyTo(ms);
byte[] array = ms.GetBuffer();
}
but this says that does not recognize path.
You are trying to access files in another application and Server.MapPath will maps a virtual path to a physical path on the server for the current application.
Server.MapPath("~") returns the physical path to the root of the application
If this two application will be deployed in the same web application it will work on the server, If not you need to create a configration for image folder that specifies the full path you need to use.
I am saving log files on a Raspberry Pi using this method to get the save path:
private static string GetFullFilePath(ISettingsReader settingsReader)
{
StorageFolder appLocalFolder = ApplicationData.Current.LocalFolder;
var logFilPath = appLocalFolder.Path + settingsReader.LogFileName;
return logFilPath;
}
The files are saved at this location on the RPi:
c$\Data\Users\DefaultAccount\AppData\Local\Packages\MyApp_ktn1kqb2ndh66\LocalState\Logs
If I open Device Portal - File Explorer I see a slightly different name for my app: User Folders\LocalAppData\MyApp_1.0.0.0_arm_ktn1kqb2ndh66
There are no files under that link.
If I search for the folder name on the RPi I can find it under c$\Data\ProgramData\Microsoft\Windows\AppRepository\Packages
Where do I have to save the files so that they are available on the Device Portal?
When creating my project I have referenced the image path as #..\..\Assets\no_picture_available1.gif was working fine, when I installed my application in other machine it says the path not available.
I tried using this one
System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + #"..\..\Assets\no_picture_available1.gif";
It shows the path as
"F:\\WindowsApp\\UI\\bin\\Debug..\\..\\Assets\\no_picture_available1.gif"
How can I set the path to Assets folder?
I found the solution to my issue, problem was with the Assets path,
when debug i set the path as different and while in release mode i set the different path.
string pathdir = Path.Combine(System.Windows.Forms.Application.StartupPath, "Assets\\no_picture_available1.gif");
#if DEBUG
return pathdir = #"../../Assets/no_picture_available1.gif";
#else
return pathdir;
#endif
i am trying to create a folder and copy some images into it using c# wpf application.
curName = txt_PoemName.Text;
// Specify a "currently active folder"
string activeDir = #"C:\Program Files\Default Company Name\Setup2\Poems";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, curName);
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);
foreach(DictionaryEntry entry in curPoem){
string newFilePath = System.IO.Path.Combine(newPath, entry.Key.ToString() + Path.GetExtension(entry.Value.ToString()));
System.IO.File.Copy(entry.Value.ToString(), newFilePath, true);
}
i have successfully created the folder and images. and also i can access them via application. but i cant see them in the location on my local disk. when i restart the machine , then application also cant see them.how can i solve this?
Sounds like you have encountered UAC Data Redirection
http://blogs.windows.com/windows/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx
You need to either force the application to run as an administrator.
How do I force my .NET application to run as administrator?
Or not save your data in a sensitive area. I would recommend saving in a subfolder of
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);