Sorry I'm completely new to Unity so I'm probably asking a stupid question. How would I play a video content from a different computer? I know that I would have to establish the remote access connection to access the specific video file located in another computer and then use the filepath of the stored video as the sourcepath to play the video from.
I guess I'm not really sure of which function to use in Unity exactly. I saw posts about movietexture function in unity, but is there any other way or can I just pass in the filepath parameter to movietexture and it will automatically start playing from the source path? Thanks
After reading your comment, it looks like all you have to do is share the folder that contains the videos file in Ubuntu. This is how you Share the folder.
Usually to access a network file, you use double backlash followed by the computer name then the file directory.
\\computername\filepath\videofilename.mp4
To use this in a code you have to escape the \ by adding another one in front of it. One \ becomes \\ and two \\ becomes \\\\.
The url to use in your code should look something like this:
"\\\\servername\\filepath\\videofilename.mp4"
This post describes is how to play video in Unity. You have to download Unity 5.6 before you can use that.
Get the script then replace:
videoPlayer.source = VideoSource.VideoClip;
with:
videoPlayer.source = VideoSource.Url;
videoPlayer.url = "\\\\servername\\filepath\\videofilename.mp4";
Related
How can I copy an image from my app to external storage with Unity Android ? I want to store an image in my app, and when the user clicks on a button it appears in the external storage. I found that I can use StreamingAssets or persistentDataPath but it looks like I can only read files from StramingAssets so I can't copy an Image. And I don't understand where my image is supposed to go in persistentDataPath and how it works. I've read the docs and looked on forums but can't find nor understand how to do it. Or is it possible to do it in android studio and then import it as a plugin or something ?
According to Unity Docs in case of Android:
Application.persistentDataPath points to /storage/emulated/0/Android/data//files on most devices (some older phones might point to location on SD card if present), the path is resolved using android.content.Context.getExternalFilesDir.
You can change the Write Permission in PlayerSettings to External (SDCard) to enable write permission to external storage:
How can I copy an image from my app to external storage...?
The short answer is: using System.IO. There are many tutorials on this topic, it depends what you want to do. Here is one example:
Sprite itemBGSprite = Resources.Load<Sprite>( "_Defaults/Item Images/_Background" );
Texture2D itemBGTex = itemBGSprite.texture;
byte[] itemBGBytes = itemBGTex.EncodeToPNG();
File.WriteAllBytes( formattedCampaignPath + "/Item Images/Background.png" , itemBGBytes );
for the past 2 days, i have been searching for a way to embed a video from my computer into my application completely so that i can send the application to other and they wouldnt need internet to play it.
the only results i got when i searched for it was to embed youtube videos, windows media player, vlc...etc into your application.
i closest i cam to finding the answer is when you embed windows media player add it in your form then use this code
axWindowsMediaPlayer1.URL = #"c:\user\myvideos\videotoplay";
but when i took the application to a friends computuer, he didnt have any location like c:\use\myvideos or even the 'videotoplay'which meant the video was not embeded completely
my last hope is to come here hoping that it is possible
thnx in advance for your help
Did you try including your video file in your project and then getting the file path to it with AppDomain.CurrentDomain.BaseDirectory so it would look like that:
axWindowsMediaPlayer1.URL = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"videotoplay");
Situation
this is probably a really simple question with a really simple answer, but I can't find the answer anywhere, so I'm going to ask here, I've been working around this because it isn't a huge issue for me, but it will be when I submit my work.
Problem
I have a soundplayer, it works fine on my PC and does exactly what I want it to do on this PC.
SoundPlayer player = new SoundPlayer(#"C:\Users\Font\Desktop\GRADED_UNIT_SOLUTION_PLANNING_UPDATED\HillRacingGraded\HillRacingGraded\Resources\Audio\" + track + ".wav");
The problem is the path.
because of THIS path my program won't work on ANY other System apart from the one it's working on right now. It crashes soon after startup.
And.. as you can probably see from the path, it's going to eventually be graded, so my lecturer will need to use this program without having to switch around a directory.
How can I get the Soundplayer path to start at "HillRacingGraded\ ...\ ..."?
Rather than it starting at the C: drive.
If you're using System.Media.SoundPlayer, it supports reading of sound files from streams and I've seen it successfully used in the past from the UnmanagedResourceStream you get from an embedded resource. So one option would be to embed your sound file as a resource in your application and play it from there.
If embedding the file isn't an option, you can get paths relative to your executable folder using code similar to that shown below. Then you just have to provide your executable and the resource files in a subdirectory (but be careful with GetExecutingAssembly() if there's any chance your code is in a DLL and can be hosted by an arbitrary executable).
var assembly = Assembly.GetExecutingAssembly();
var folder = Path.GetDirectoryName(assembly.Location);
var soundFile = Path.Combine(folder, "MySoundFile.wav");
The special folder path helpers can also reduce the hard-coding but work best when your application will be installed via an installer and you can put files in the appropriate places automatically (which isn't likely to be the case for a school project).
For me (VS 2022, .net 6, C # 10) it worked:
Import the "file.wav" file into the main directory.
Change in: Properties (file.wav) - Copy to Output Directory to: Copy always.
Later it was enough to:
SoundPlayer player = new SoundPlayer("file.wav");
player.Load ();
player.Play ();
i am trying to make a code which takes an image from a file path which i type in manually.
here is my code:
pieceImage = Image.FromFile(#"O:\Projects\imagename.png");
This code is saved on my USB flash drive.
However, whenever i run this code on a different computer, the path is different (obviously) and doesn't necessarily start with O:\ but something else, for example F:.
What can i use so that the path will change accordingly to the computer on which it runs? many thanks in advance.
You could get the drive letter based on the drive name, then build the Path to the file based on that (so only use the relative path from the root of the drive, no letter). See the DriveInfo class on MSDN and this question for a practical example of usage.
Of course, if the image is not on the USB drive, you will need to be more creative. But then I would recommand a different approach all the same, because there might be a design flaw in all this.
Assuming your program is in directory /Program/, include all images under your /Program/ directory, such as /Program/Images/. That way the images will be available no matter where the program is run.
My project is to build a simple game and for now I only made the Main Menu Form1 with 5 buttons. The buttons have a MouseClick and MouseEnter on them, and I have a background music track using a WMP method (using WMPLib and axWMPLib).
My problem is when I'm taking the bin/debug putting it on a rar file and giving it to my friends, they say they don't hear the sound. I made the project trough WMP version 11, so I asked them if their WMP version is 11 and they said yes. I have no idea why I hear the sounds on my computer and they don't.
I tried to give them the folders:
bin\Release
bin\Debug
x86\Release
x86\Debug
but they still said that they can't hear any sound from all of them.
EDIT
All my sounds are in a folder called "Sounds". I found some details and found out that you need to embeding those WMP sounds to "Resources".
So how can I do that, and how I call them when Form1 loads up. And no, this following code doesn't work:
BackGround.URL = Properties.Resources.Invincible;
It says I can't convert System.IO.UnmanagedMemoryStream to String.
Sincerely I don't recommend you to use WMP, so give a look to the SoundPlayer class.
However I think the problem is that you don't give the correct location to your files. So what you can do is to locate your files in your application folder, get its location and create the location of the music files.
So try:
string musicName = Application.StartupPath + "music.mp3";
Or if you have a Sounds folder in the application path use:
string musicName = Application.StartupPath + "\\Sounds\\music.mp3";
Else if you insert your music file in the application resources this:
BackGround.URL = Properties.Resources.Invincible;
didn't work because BackGround.URL is of type string while Properties.Resources.Invincible is the music file stream.
I don't know if using WMP you can set the stream from where it can play the file. Although the SoundPlayer class I linked previously contains a property from where you can set the input stream. You can do it in this way:
SoundPlayer mySoundPlayer = new SoundPlayer();
mySoundPlayer.Stream = Properties.Resources.Invincible;
mySoundPlayer.Load();
mySounPlayer.Play(); //plays the Properties.Resources.Invincible sound