Anybody knows how to turn On/Off android display backlight using C# only in Unity? I don't like plugins, and I don't want to make one of my own.
I know that you can disable the display while using the proximity sensor... but i don't know how to do it in C# in Unity3d...
Maybe the android.provider.Settings.System.SCREEN_BRIGHTNESS will help but i don't know how to change the value (1-255) in Unity3d with C#
If someone have a solution i would be very happy.
thank you
M.
i've try'ed this but i did not get any result...
public void CheckScreenBrightness()
{
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var context = actClass.GetStatic<AndroidJavaObject>("SCREEN_BRIGHTNESS");
AndroidJavaClass systemGlobal = new AndroidJavaClass("android.provider.Settings$Global");
var screenbrightness = systemGlobal.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "SCREEN_BRIGHTNESS");
Debug.Log("Screen Brightness = " + screenbrightness);
}
}
Related
So when I tried to build my unity project the options menu did not build correctly. I tried two unity version, a hard restart of my system, and changing settings. Nothing corrected the issue. The game works fine in the unity editor but does not work correctly when built.
Editor drop-down (How it should be):
Build drop-down (How it should not be):
If you look in the build picture it duplicates all the drop-down entries which may be cause by the script that generates it:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class OptionsMenu : MonoBehaviour
{
public AudioMixer audioMixer;
public Dropdown resolutionDropdown;
Resolution[] resolutions;
void Start()
{
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + "X" + resolutions[i].height;
options.Add(option);
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
{
currentResolutionIndex = i;
}
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
The other problem is with the quality dropdown, In the editor it works fine but when I build it it does not change the game quality (It stays on low).
The other problem has only occurred on one build. The problem was that the mouse sensitivity to move the camera was very low, when I built it again the problem was fixed.
For duplicates, it's a known problem: the problem is on standalone where it appears to duplicate each resolution with refresh rates of 60Hz and 48Hz.
For example: 640x480#48Hz; 640x480#60Hz; etc
A solution could be a Linq statement, selecting only 60Hz frequencies (or 48Hz):
var resolutionsIEnumerable = Screen.resolutions.Where(resolution => resolution.refreshRate == 60);
resolutions = resolutionsIEnumerable.toArray();
Linq Where() returns IEnumerable so, you have to convert to array Resolution[] (with toArray())
In order to change resolution, you have to use
Screen.SetResolution(640, 480, true, 60);
You should change 640 and 480 on dropdown change with the selected resolution.
I am putting together a winforms app using libvclsharp wrapper.
It is a basic app that hosts 4 x VideoView windows and plays 4 different mp4 videos.
It plays ok and seems stable mostly, but the lib has some odd quirks that i cant seem to find an answer to
I need to click a button on the form and sent all the videos to a specific time, they are all the same length at the moment
using
_mediaPlayer1 = new MediaPlayer(_libVLC1);
_mediaPlayer2 = new MediaPlayer(_libVLC1);
_mediaPlayer3 = new MediaPlayer(_libVLC1);
_mediaPlayer4 = new MediaPlayer(_libVLC1);
media1 = new Media(_libVLC1, #"D:Video.mp4", FromType.FromPath);
media2 = new Media(_libVLC1, #"D:Video2.mp4", FromType.FromPath);
media3 = new Media(_libVLC1, #"D:Video3.mp4", FromType.FromPath);
media4 = new Media(_libVLC1, #"D:Video4.mp4", FromType.FromPath);
_mediaPlayer1.Media = media1;
_mediaPlayer2.Media = media2;
_mediaPlayer3.Media = media3;
_mediaPlayer4.Media = media4;
videoView1.MediaPlayer = _mediaPlayer1;
videoView2.MediaPlayer = _mediaPlayer2;
videoView3.MediaPlayer = _mediaPlayer3;
videoView4.MediaPlayer = _mediaPlayer4;
so to send all 4 to same time i use
foreach (var player in _PlayersCollection)
{
player.Time = 12000);
}
the problem is when click button the if the videos are playing it moves straight to the new time location.
if the videos are paused the videos twitch like they are moving just one frame, then you if click again they jump to the right time location.
this is very annoying and i cant see a reason why.
I saw a tip online to suggest setting the output renderer for the lib to D3d9 instead of D3d11 but i cant find any examples of how to change that for this lib.
Does anyone have any suggestions please who is familiar with lib on winforms.
thanks
I also noticed this problem in vlc.dotnet
Looks like the player does not like it's time too be changed to fast.
My solution was to limit the update rate of my tracker.
Some thing similar may work for you.
long lngLastScrollTimeStamp=0;
private void trkVideo_Scroll(object sender, EventArgs e)
{
if (((Stopwatch.GetTimestamp() / TimeSpan.TicksPerMillisecond) - lngLastScrollTimeStamp) > 250)
{
vlcControl1.Time = trkVideo.Value;
lngLastScrollTimeStamp = Stopwatch.GetTimestamp() / TimeSpan.TicksPerMillisecond;
}
}
I'm working with MOGRE 1.8.1 to embed 3D models within a WPF application. I've run into an issue where the application crashes when the user changes resolution or their computer goes to sleep. I believe this is because the render system is trying to draw to a surface that it doesn't have access to anymore.
I'm not exactly sure what to do; I've tried using the dispose method to kill MOGRE and reboot it later (by catching the windows event), but have run into a memory leak. The pause render method included within the MOGRE library does not seem to work either. Does anyone have any ideas on how to circumvent this issue?
Notes
You can find the example I'm running here. Main difference is that I'm using the 1.8.1 .dlls instead -> http://www.codeproject.com/Articles/29190/Blend-the-OGRE-Graphics-Engine-into-your-WPF-proje , but the error is present in both.
OgreImage.cs is where the issues are happening.
Thank you for your help.
This error happen when the device is lost, so you have to add your control in the function RenderFrame()
//WallPaper, CTRL + ALT + DEL, etc
if (this.isDeviceLost)
{
//Recreate the texture render
ReInitRenderTarget();
//Restore device lost
_renderWindow._beginUpdate();
_renderWindow._endUpdate();
_reloadRenderTargetTime = -1;
this.isDeviceLost = false;
}
And this is my ReInitRenderTarget() function
protected void ReInitRenderTarget()
{
DetachRenderTarget(true, false);
DisposeRenderTarget();
_texture = TextureManager.Singleton.CreateManual(
"OgreImageSource RenderTarget",
ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
TextureType.TEX_TYPE_2D,
(uint)ViewportSize.Width, (uint)ViewportSize.Height,
0, Mogre.PixelFormat.PF_R8G8B8A8,
(int)TextureUsage.TU_RENDERTARGET);//, null, false, 8);
_renTarget = _texture.GetBuffer().GetRenderTarget();
_reloadRenderTargetTime = 0;
int viewportCount = ViewportDefinitions.Length;
viewports = new Viewport[viewportCount];
for (int i = 0; i < viewportCount; i++)
{
Viewport viewport;
ViewportDefinition vd = ViewportDefinitions[i];
viewport = _renTarget.AddViewport(vd.Camera, zIndexCounter++, vd.Left, vd.Top, vd.Width, vd.Height);
viewport.BackgroundColour = vd.BackgroundColour;
viewports[i] = viewport;
}
var ev = ViewportsChanged;
if (ev != null) ev();
viewportDefinitionsChanged = false;
}
So, I was redding a article(this one : https://dashingquill.wordpress.com/2012/06/27/capturing-webcam-using-directshow-net-library/ ) and i download it to study the code.
Im trying to implemente this changes(to make video in 1920x1080) :
capture.FrameRate = 29.997;
capture.FrameSize = new Size(1920, 1080);
capture.AudioSamplingRate = 44100;
capture.AudioSampleSize = 16;
But my ask to you is where in code do i apply this codes?
I try to apply here :
void preview()
{
try
{
capture = new Capture(filters.VideoInputDevices[0], filters.AudioInputDevices[0]);
capture.FrameRate = 29.997;
capture.FrameSize = new Size(1920, 1080);
capture.AudioSamplingRate = 44100;
capture.AudioSampleSize = 16;
capture.PreviewWindow = panel1;
but when i do that something funny happens, my video is in (1920x1080) only when i click on "stop" anything different make the preview video "weird"(not in 192x1080).
Can you help me on that?
Aa, another question. If i want to capture a sigle frame,like a picture,how can i do that with that code?
Thank you and osrry for my bad english . Its not my natural language.
I found by myself the solution.
Well, apparently what i was doing is correct, but i was running on debug mode. When a change to realese thats works fine and the framesize was set correct.
I know we have some similar questions already but all of them can not help me solve my issue (because of the difference platform). So I put my question here with a hope that someone can help me.
I am working on a xamarin project and using Google Map API ver 2 to make a map.
When I touch on the map, I will add a new marker by using this code.
public void AddPoint(LatLng pointPossition)
{
MarkerOptions markerPoint = new MarkerOptions();
markerPoint.Anchor (0.5f, 1.0f);//The same issue occur when I remove this line
markerPoint.InvokeIcon(m_PointMoveableIcon);
markerPoint.SetPosition (pointPossition);
markerPoint.Draggable (true);
Marker marker = m_Map.AddMarker(markerPoint);//m_Map is the Google Map
m_Markers.Add(marker);//m_Markers is a list to store all created markers
}
By that way, I can create some makers on the map
All markers are draggable, so I can long click on any marker and drag it to another position, but unfortunately, the dragged marker change position suddenly, and this behavior is really bad.
I tried many solutions but not work. So, I hope someone can help me.
Thank in advance.
I had this quest now. And it's my solution is code below.
Why first number is it, i don't know, but it's works for my debugger. And 0.5 probably is half marker position.
private void Map_PinDragging(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801 * 0.5), e.Pin.Position.Longitude);
}
private void Map_PinDragStart(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801 * 0.5), e.Pin.Position.Longitude);
}
Pin DragPin;
private void Map_PinDragEnd(object sender, PinDragEventArgs e)
{
int m = map.Pins.IndexOf(e.Pin);
map.Pins.ElementAt(m).Position = new Xamarin.Forms.GoogleMaps.Position(e.Pin.Position.Latitude - (0.001347153801*0.5), e.Pin.Position.Longitude);
}
And...
This value change with my map Zoom. Needs some math there.