How to open URL in Virtual Reality (GearVR) App - c#

I would like to know how to open URL on button click in Gear VR App. Samsung Internet App in Oculus Store can be used in this scenario. Just like in 2D Non-VR Android Application, URL is automatically opened in Chrome or Firefox based on default browser. But in Gear VR app when I call
Application.OpenURL("http://www.google.co.uk");
the app freezes.
If this is not possible at all, then is there a way to show intractable Web-View in 3D space?
Any kind of help will be appreciated.

I had found the solution from this post on Oculus forum.
Here is the working code:
public class OpenWebsiteOnHeadsetRemove : MonoBehaviour
{
#region Serialized
public OVRManager m_OVRManager;
#endregion
#region Variables
private bool m_UserPresent = true;
private bool m_HasOpenedURL = false;
#endregion
#region Lifecycle
private void Update () {
#if UNITY_ANDROID
bool isUserPresent = m_OVRManager.isUserPresent;
if( m_UserPresent != isUserPresent )
{
if( isUserPresent == false && m_HasOpenedURL == false && Application.isEditor == false )
{
m_HasOpenedURL = true;
Application.OpenURL("http://www.google.co.uk");
}
}
m_UserPresent = isUserPresent;
#endif
}
#endregion
}
It will wait until the user has removed the headset before opening the
app to avoid the jarring visuals of the app freezing when you try to
open the URL. If the player takes the headset off and puts it back on
they will be returned to where they were in the game.
Hope this helps late users :)
Courtesy: Glitchers Games

Related

SharpDx in Unity3D - Buttons does not work anymore when click other window of editor

As you most probably know, Unity3D have terrible buil-in input system what is unable to change configuration runtime so i decised to write own input system based on SharpDX DirectInput. I know well directInput is not officialy recomendet but i like it for its ability to work with device of all kinds (Like Trust dual stick gamepad GTX 28 of mine. Originaly purchased for PSX emulation).
I using class below to representate button object
public class InputButton
{
public JoystickOffset button;
public Key key;
public int pressValue;
public int relaseValue;
public bool isJoystick;
public InputButton(JoystickOffset button, int pressValue, int relaseValue)
{
this.button = button;
this.pressValue = pressValue;
this.relaseValue = relaseValue;
isJoystick = true;
}
public InputButton(Key key, int pressValue, int relaseValue)
{
this.key = key;
this.pressValue = pressValue;
this.relaseValue = relaseValue;
isJoystick = false;
}
}
Then i replace Unity's (pretty terrible method by the way) Input.GetKeyDown with my own (If you name class same as one of unity's classes you replace it. I know someone must not like use of static here but i see it very benefical)
public static bool GetKeyDown(InputButton button)
{
bool pressed = false;
keyboard.Poll();
keyboardData = keyboard.GetBufferedData();
if (button.isJoystick == false)
{
foreach (var state in keyboardData)
{
if (state.Key == button.key && state.Value == button.pressValue)
{
pressed = true;
}
}
}
return pressed;
}
But before everything i call Input.Initialize() from another class (during Awake()). it looks like this :
public static void Initialize()
{
directInput = new DirectInput();
var joystickGuid = Guid.Empty;
foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Joystick, DeviceEnumerationFlags.AttachedOnly))
{
joystickGuid = deviceInstance.InstanceGuid;
}
if (joystickGuid == Guid.Empty)
{
foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly))
{
joystickGuid = deviceInstance.InstanceGuid;
}
}
if (joystickGuid != Guid.Empty)
{
joystick = new Joystick(directInput, joystickGuid);
joystick.Properties.BufferSize = 128;
joystick.Acquire();
}
keyboard = new Keyboard(directInput);
keyboard.Properties.BufferSize = 128;
keyboard.Acquire();
}
Now to the problem. When i click to anything outside game window in the editor, keys does not respond anymore. I checked everything and both directInput and keyboard are still in variables. Most likely some problem with "Focus" of window because this problem looks like directInput instance or keyboard gets disconnected as soon as game window lost focus (focus is lost when window is not active window, active window is not "active" but so called "focused").
Do someone know why this happenig and how to repair it ?
EDIT : Looks like this problem is somehow connected to window(s). I have settings and i'm able to switch fullscreen runtime. As long as i'm in fullscreen it works fine but when i switch to window it stop working.
Thanks.
-Garrom
Now i see myself as very stupid person... Anyway i was right abou window focus. When game window lost focus it (somehow) break directInput. I solved this useing unity's callback OnApplicationFocus and re-Initialize (call Initialize(). See original question) every time game window gets focused.

Control the intensity of the flash light in xamain.forms

i am new to xamarin forms. now 'm developing a sample application for making a Torch. i got a nuget for On/Off the flash light. https://github.com/kphillpotts/Xamarin.Plugins/tree/master/Lamp . but i like to control the intensity of the flash light. i tried to use the native code but failed to do it. i search the google but cant find it .is there any way i can make it for achieving it.
Thank you in advance
I don't know a plugin that implements it. But you can easily extend the lamp plugin.
You could extend the interface ILamp like
public interface ILamp
{
///....
void TurnOn(float intensity);
}
then implement it by copying the TurnOn functionality
iOS
public void TurnOn(float intensity)
{
var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);
if (captureDevice == null)
{
Debug.WriteLine("No captureDevice - this won't work on the simulator, try a physical device");
return;
}
NSError error = null;
captureDevice.LockForConfiguration(out error);
if (error != null)
{
Debug.WriteLine(error);
captureDevice.UnlockForConfiguration();
return;
}
else
{
if (captureDevice.TorchMode != AVCaptureTorchMode.On)
{
captureDevice.TorchMode = AVCaptureTorchMode.On;
NSError err;
captureDevice.SetTorchModeLevel(intensity, out err); // add this line
}
captureDevice.UnlockForConfiguration();
}
}
On Android I'm not sure if there is a API to control it. I can't find one. If there is one, just proceed like on iOS.
If the platform has no API, just implement TurnOn(float intensity) like
public void TurnOn(float intensity)
{
TurnOn();
}

axWindowsMediaPlayer: Black Screen on looping

I have created a Windows Form Application having axWindowsMediaPlayer control. I haven't created a playlist on it, but I have stored my .mp4 files at a particular location. I pass the path to my next video at Media Ended state. For the first time, the player receives the correct path and play. But for the second video, I can only see a black screen although the player is receiving the correct path to play.
Here is my code for Media Ended State:
private void axWindowsMediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if(e.newState == 8)
{
//Getting jumpTo of selected page
var selectedElementJumpToValue = MainContentAreaBl.GetSelectedElementValue(_currentId, "jumpTo");
if (selectedElementJumpToValue != null)
{
_currentId = selectedElementJumpToValue;
if (_currentId != "menu")
{
pagination.Text = MainContentAreaBl.GetPaginationText(_currentId);
LaunchPlayer(selectedElementJumpToValue);
}
else
{
this.Hide();
this.SendToBack();
menu.BringToFront();
}
}
}
}
private void LaunchPlayer(string id)
{
string selectedElementPageTypeValue = MainContentAreaBl.GetSelectedElementPageTypeValue(id);
var playerFile = Path.Combine(Common.ContentFolderPath, MainContentAreaBl.GetSelectedElementDataPathValue(id));
if (selectedElementPageTypeValue == "video")
{
InitialiseMediaPlayer();
axShockwaveFlash.Stop();
axShockwaveFlash.Visible = false;
if (File.Exists(playerFile))
{
axWindowsMediaPlayer.URL = playerFile;
}
}
else if (selectedElementPageTypeValue == "flash")
{
InitialiseShockwaveFlash();
axWindowsMediaPlayer.close();
axWindowsMediaPlayer.Visible = false;
if (File.Exists(playerFile))
{
axShockwaveFlash.Movie = playerFile;
axShockwaveFlash.Play();
}
}
}
private void InitialiseMediaPlayer()
{
axWindowsMediaPlayer.Visible = true;
axWindowsMediaPlayer.enableContextMenu = false
axWindowsMediaPlayer.uiMode = "none";
axWindowsMediaPlayer.Dock = DockStyle.Fill;
}
When I debugged my application, I saw Media Player getting the correct path after e.newState == 10 (Ready state). What am I doing wrong?
Edit 1: I found out that after my current video enters into Media Ended state, the player is stopped from playing. Even if I write axWindowsMediaPlayer.ctlControls.play();, it doesn't affect the media player. Is this a bug from in axWindowsMediaPlayer?
I have encountered this issue before as well. The most likely cause is that you are giving the command axWindowsMediaPlayer.ctlControls.play(); while the play state is still changing ( after Media Ended, it will change to Ready state). If a command is sent to the player while the play state is changing, it won't do anything. Another possible cause of your error is that sometimes Media State 9 (transitioning) needs to be included with if(e.newState == 8) such that you have if(e.newState == 8 | e.newState==9). I have had cases where it doesn't pick up on State 8 (media ending), possibly because it happens really fast and jumps to transitioning - not completely sure of this cause but I had a player that wasn't moving to the next video in the playlist because of this happening. To solve this I did something like:
if (e.newState == 8 | e.newState== 9 | e.newState== 10)
{
if (e.newState == 8)
{ //Insert your code here
}
This would vary slightly depending on what you are trying to achieve. Another thing to watch out for is using the PlayStateChange Event to set the Video URL, this causes problems as a result of re-entry problems with WMP - see other posts for further explanation on my last comment:
here is a good one and another here. Hope this helps!

Is there a way to stop audio on Android when my app crashes or hangs?

I've written an app for Android using Xamarin Studio. Occasionally, due to other code, the app will hang and become unresponsive. When the user clicks the home button, the audio continues to play instead of stopping. Is there a way for a "hung" app to know that it has been put in the background and force the audio to pause?
protected override void OnDestroy ()
{
DependencyService.Get<IMediaController>().Stop();
// Call base method
base.OnDestroy ();
}
protected override void OnSleep()
{
DependencyService.Get<IMediaController>().Pause();
}
I've determined that the way to do this is to monitor the Android running tasks. This enables me to determine if my app has been backgrounded. I have a thread which runs throughout the apps lifetime, and it is normally killed in OnSleep. If OnSleep is not called, then that thread will determine the app is non-responsive, and it will call OnSleep. This is for Xamarin. I got my ideas from this post. how to check the top activity from android app in background service
//Returns the top running task information
private static ActivityManager activityManager;
private static Android.App.ActivityManager.RunningTaskInfo runningTaskInfo;
public static ComponentName GetTopActivity()
{
if(activityManager == null)
{
activityManager = (ActivityManager) Application.Context.GetSystemService(Context.ActivityService);
}
IList<Android.App.ActivityManager.RunningTaskInfo> runningTasks =
activityManager.GetRunningTasks(1);
if(runningTasks != null && runningTasks.Count > 0)
{
runningTaskInfo = runningTasks[0];
return runningTaskInfo.TopActivity;
}
else
{
return null;
}
}
//This called from my thread every 2 seconds
public bool IsAppVisible()
{
//have to do a complicated version of this to determine the current running tasks //and whether our app is the most prominent.
Android.Content.ComponentName componentName = AndroidUtils.GetTopActivity();
bool isCurrentActivity;
if(componentName != null)
{
isCurrentActivity = string.Compare(componentName.PackageName, "myPackage") == 0;
}
else
{
isCurrentActivity = false;
}
return isCurrentActivity;
}
if(DependencyService.Get<IDeviceUtility>().IsAppVisible() == false)
{
//This needs to be manually called if the app becomes completely unresponive
OnSleep();
Debug.WriteLine("App is no longer visible");
}

Coded UI Test checking for an open Windows Media Player file

I am trying to create a Coded UI property that checks for an open WMP file.
public BrowserWindow VideoWindow
{
get
{
if (this._videoWindow == null || !this._videoWindow.Exists)
{
this._videoWindow = new BrowserWindow();
this._videoWindow.SearchProperties["Name"] = "Windows Media Player";
this._videoWindow.SearchProperties["ControlType"] = "Window";
}
return this._videoWindow;
}
}
Obviously, this will not work. Originally, the application opened a link to a video site. So this worked, but since it is quite a bit different than a BrowserWindow I am not sure how to do it. How can I use Coded UI to "grab" it?
The only real difference for windows media player from the video site you've been dealing with is that windows media player will be a WpfWindow instead of a BrowserWindow -
public WpfWindow VideoWindow
{
get
{
if (this._videoWindow == null || !this._videoWindow.Exists)
{
this._videoWindow = new WpfWindow();
this._videoWindow.SearchProperties["Name"] = "Windows Media Player";
this._videoWindow.WindowTitles.Add("Windows Media Player");
}
return this._videoWindow;
}
}
After that, you just have to get the controls inside of the media player window(WpfControls instead of HtmlControls) to determine which file is open.

Categories