I want to avoid users having to scan the QRCode with the Cardboard Viewer profile on it so that they can just place their device into the viewer and be ready. The viewer configuration is constant and I have a profile URL for it. Is it possible to load this profile at the application start up in Unity3D and if so how should I do it?
I tried setting it up by loading the following line of code at the Start of a Script attached to a camera but without any luck:
Cardboard.SDK.DefaultDeviceProfile = new Uri(SpecificVRViewerProfileUrl);
I'm using Unity 5.3.1f1, Cardboard 0.6, and Vuforia.
I haven't used the Unity SDK for cardboard, only java, but looking through the sample (https://github.com/googlesamples/cardboard-unity/blob/master/Cardboard/Scripts/Cardboard.cs) you might want to try getting a device reference using BaseVRDevice. It's a class also in the samples (https://github.com/googlesamples/cardboard-unity/blob/master/Cardboard/Scripts/VRDevices/BaseVRDevice.cs)
// The VR device that will be providing input data.
private static BaseVRDevice device;
device = BaseVRDevice.GetDevice();
device.Init();
and then setting the device profile with this instead of Cardboard.SDK.SetDefaultDeviceProfile
public Uri DefaultDeviceProfile = new Uri("your URL here");
if (DefaultDeviceProfile != null) {
device.SetDefaultDeviceProfile(DefaultDeviceProfile);
}
Related
I program C# Android app using Xamarin. I wrote this code:
protected MediaPlayer player;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.layout1);
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
player = new MediaPlayer();
player.Reset();
var fileDescriptor = Assets.OpenFd("MySound.mp3");
player.SetDataSource(fileDescriptor.FileDescriptor);
player.Prepare();
player.Start();
}
MySound.mp3 file is direct in the Assets folder. When I run app there is an error:
Java.IO.IOException
Message=Prepare failed.: status=0x1
in the line with player.Prepare();
What is wrong? Why it's no working?
This seems to be a common exception with MediaPlayer.Prepare() on Android devices. A quick search turned up this:
https://social.msdn.microsoft.com/Forums/en-US/15f9c371-1b8d-4927-9555-f40e2829c377/mediaplayer-prepare-failed-stauts0x1?forum=xamarinandroid
Quote by Anonymous:
Hi, I wasted a lot of time, trying to find a solution to this issue on
my side too. So I post here, just in case it is helping some people.
My situation : I wanted to load an audio file from my assets (so not
registered in my resources). I am using a similar code as Ike Nwaogu,
except that I am using an AssetFileDescriptor to open my file (in my
activity class code, so I have access to "Assets") :
string path = "Audio/myfile.ogg";
Android.Content.Res.AssetFileDescriptor afd = Assets.OpenFd(path);
MediaPlayer soundPlayer = new MediaPlayer();
if (afd != null)
{
soundPlayer.Reset();
soundPlayer.SetDataSource(afd.FileDescriptor);
soundPlayer.Prepare();
soundPlayer.Enabled = true;
afd.Close();
}
I was failing on the Prepare(). I tried to add the access to external
storage permissions (but it did make sense since it
was loaded from my assets directly, I tried just in case).
Just by chance, by seeing other people samples on the forums, I added
the afd.StartOffset, afd.DeclaredLength to the parameters:
soundPlayer.SetDataSource(afd.FileDescriptor, afd.StartOffset,
afd.DeclaredLength);
and it worked ... I don't know if it just luck and if is going to fail
again later or if there is a bug in API ...
According to various sources, using getStartOffset and getLength when setting the DataSource should fix this:
player.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getLength());
Alternatively, here are a few more ideas:
Android MediaPlayer throwing "Prepare failed.: status=0x1" on 2.1, works on 2.2
https://forum.processing.org/two/discussion/6722/andriod-mediaplayer-prepare-failed-status-0x1
I'm working on a Cities: Skylines mod and I want to access the sharedassets.assets file(s) the game has in the Data folder programmatically to get a mesh/prefab.
I've found a tool called Unity Assets Bundle Extractor (UABE) and it is able to open up these files and extract the mesh.
Is there a way to extract a mesh from the sharedassets programmatically with C# code like UABE does?
I've looked in the Unity documentation but so far only have seen this page (not sure if relevant): https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromFile.html
I tried adapting the code from there but I haven't had any success so far, only have had not found error messages
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath, "sharedassets11"));
Is there a way to achieve this? Thanks
Look at the API for AssetBundle.LoadFromFile.
There is a second method AssetBundle.LoadAsset (or alternatively also maybe AssetBundle.LoadAllAssets) you will need:
var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.dataPath, "sharedassets11"));
if (myLoadedAssetBundle == null)
{
Debug.Log("Failed to load AssetBundle!");
return;
}
var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("NameOfTheAccordingObject");
Instantiate(prefab);
myLoadedAssetBundle.Unload(false);
I need to integrate a video stream from my Macbook camera using a Xamarin.Mac form. However, all of the documentation that I find only tells you how to do so in iOS and Android platforms.
How would you go at getting a video stream from a Macbook then? Any libraries I should look at?
You will want to review the AVFoundation APIs (QTKit is deprecated).
You can create a custom Xamarin.Forms View renderer based on a NSView and assign the AVCaptureVideoPreviewLayer as the control's layer to stream the camera output to this control.
Store class level references to following and make sure you Dispose them when your control goes out of scope otherwise there will be leaks:
AVCaptureDevice device;
AVCaptureDeviceInput input;
AVCaptureStillImageOutput output;
AVCaptureSession session;
In your capture setup, you can grab the default AV device assuming you want to use the build-in FaceTime Camera (also known as iSight).
macOS/Forms Example:
device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
input = AVCaptureDeviceInput.FromDevice(device, out var error);
if (error == null)
{
session = new AVCaptureSession();
session.AddInput(input);
session.SessionPreset = AVCaptureSession.PresetPhoto;
var previewLayer = AVCaptureVideoPreviewLayer.FromSession(session);
previewLayer.Frame = Control.Bounds;
Control.Layer = previewLayer;
output = new AVCaptureStillImageOutput();
session.AddOutput(output);
session.StartRunning();
}
Note: A lot of the AVFoundation framework is shared between iOS and MacOS, but there are some differences so if you end up looking at iOS sample code be aware you might need to alter it for macOS.
https://developer.apple.com/documentation/avfoundation
I am able to create media player like app using VLC.Net library. I am now trying to add a feature to be able to select the output device to play the media through. So far no luck.
Has anyone ever done it?
From reading the source code I would try the following. I assume you have a VlcMediaPlayer at hand and created somewhere:
void DoAudio(VlcMediaPlayer player)
{
IAudioManagement audioMgt = player.Audio;
foreach(AudioOutputDescriptions descriptions in audioMgt.Outputs.All){
foreach(AudioOutputDevice device in description.Devices){
//enumerate them for display
string audioName = device.LongName;
// Or set it as output
device.SetAsCurrent();
}
}
I Want Create a Win-Form Application Can be Connect to a Digital Camera Attached to My Computer.I Want See a LiveView of Persenels in Computer And Then Take a Picture of Persenels.
How Can I Implement This Action?
What Camera Can I Use?
What Component Or Library Can I Use??
What SDk Tools Can I Use??
Please Help me...
You can do this with the Windows Image Acquisition API. Get this started with Project + Add Reference, Browse tab, navigate to c:\windows\system32\wiaaut.dll. That's a COM component, you'll get an interop library for it with interface types in the WIA namespace.
First thing you want to do is get a reference to the camera, use WIA.ShowSelectDevice(). It returns a Device object if there's only one camera attached, a dialog to let the user select if there are more. Like this:
public static WIA.Device SelectCamera() {
var dlg = new WIA.CommonDialog();
try {
return dlg.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, false);
}
catch (System.Runtime.InteropServices.COMException ex) {
if (ex.ErrorCode == -2145320939) return null;
throw;
}
}
That ought to get you started. Check out the code snippets at this MSDN page for more of the thing you can do with the API. Beware that not all cameras allow you do use them interactively when they are attached to the machine. My cheapo point-and-shoot doesn't.