Unity3D VideoPlayer Clip Crashes on Android but Not W10 Desktop - android

When launching the game, after the unity splash screen, my first scene is a small 15-seconds .mp4 cinematic.
I have scripted said cinematic to load the next scene (Main Menu UI) after it has ended and it works flawlessly on desktop. When I build&run to test it on my Android device (Huawei P20), it crashes after the Unity splash screen.
I've tried using multiple .mp4 as well as using converters to change their codec to no avail. I've also tried resizing and/or changing the resolution, but that wouldn't fix it either.
My only limited solution is using Handheld.PlayFullScreenMovie, but this is not something I want since I don't want players to be able to pause/skip the cinematic.
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.SceneManagement;
public class IntroToMainMenuUI : MonoBehaviour
{
public VideoPlayer VideoPlayer;
void Start()
{
VideoPlayer.loopPointReached += LoadScene;
}
voice LoadScene(VideoPlayer vp)
{
SceneManager.LoadScene("Main Menu UI");
}
}
Needless to say, the Android device always crashes, while the W10 desktop runs it perfectly.

For anyone in the future in a similar predicament, I resolved it. The fault was that I had the video clip attached to the main camera directly. Apparently desktop will play it fine as is, but on Android it will always crash. I, instead, went to the Video Player component and in "Render Mode" I chose "Render Texture". I then created a raw image and attached the Video Clip in the "Texture" section. Like-wise, I then attached the raw image into the Video Player's "Target Image" section. It played fine afterwards.

Related

Xamarin forms Android SurfaceView - still video image left behind

In my Xamarin forms Android app, I play videos in view 1 and 16 in a matrix of 16 views using Android SurfaceView integrating with third-party video SDK, see screenshot below. Then I switch to 4 views. On switching, I stopped both videos first and then resume playing. It still plays video in view 1 which is correct. But it also shows a still video image left behind (from previous view 16). Th surface view of this image should have been removed. What could be the cause of the image?
I can clear a video or image and detach the camera using the following code. We do have such a command button Clear All.
public int ClearVideo(int cameraIndex)
{
if (App.CameraToViewHolderDictionary.ContainsKey(cameraIndex))
{
var surfaceHolder = (ISurfaceHolder)App.CameraToViewHolderDictionary[cameraIndex];
if (surfaceHolder != null/* && surfaceHolder.Surface.IsValid*/)
{
surfaceHolder.SetFormat(Format.Transparent);
surfaceHolder.SetFormat(Format.Opaque);
}
}
_videoViewModel.DetachCamera(cameraIndex);
return 0;
}
However this code shouldn't be required when changing the size of matrix views. Please suggest a way to get rid of the image left behind. Thank you.
I understand that this may not be an issue of Xamarin forms. Please note that the app works on some Android versions such as Pixel 3 or emulators such as bluestacks.

Unity App freezes when loading Multiple Videos on same Scene

When navigating from menu to a Scene that contains 8, 1-minutes MP4 videos, that are played using new VideoPlayer script on RawImage component. I am using Unity 5.6.0b11 beta version.
In the scene that I am trying to navigate has prefabs that loads videos in list thumbnails, previously I was loading Images instead of Videos and it was working fine, now when trying to load video it freezes for than 38 seconds on Axon 7 (4GB RAM) and 32 seconds on One Plus 3 (6 GB RAM) but does not lags at all when playing on Unity Player itself.
Script I used for VideoPlayer is from this StackOverflow Question.
button.onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
{
SceneManager.LoadSceneAsync("SceneSponsors");
StartCoroutine(CloseMenu());
}));
Is there a way, I can work around with the Slow Loading Scenes or pre-load them in Background when mainScene is loaded on the App start and navigate in need.
I saw somewhere Resources.Load() also makes it slow on Android Devices, but I've tested by removing all Resources.Load() which I was using to load image sprites but the problem was still there.
Edit:
Here's my CloseMenu() functions it is only used to swipe and move the menu panel. P.S the App freezes only on loading that particular Scene, and works smoothly for other.
IEnumerator CloseMenu()
{
if (IsOpen)
{
Vector3 pos = MainMenuWindow.transform.position;
iTween.ColorUpdate(CloseArea, new Color(0, 0, 0, 0f), .6f);
iTween.MoveTo(MainMenuWindow.gameObject, new Vector3(Screen.width, pos.y, pos.z), .6f);
IsOpen = false;
yield return new WaitForSeconds(.3f);
CloseArea.transform.position = new Vector3(-240 * ScaleFact, CloseArea.transform.position.y, CloseArea.transform.position.z);
}
}
Edit 2
I am loading VideoPlayer on RawImage using Script. Here's what RawImage looks like in Play mode along with VideoPlayer, and in inactive mode.
For my case of problem. I had to make some changes on the VideoPlayer API Script I was using from this StackOverflow Question
In the script I was using from that link. The Co-routine was started inside the Start() function, that made the videos in 8 different prefab, to load at once even they were in pause mode.
So I added a new function PlayVideoOnClick() and attached it to the Click Event of the RawImage, so now the video will be loaded only if the RawImage is clicked.
Changed from
public void Start()
{
Application.runInBackground = true;
StartCoroutine(playVideo());
}
To
public void PlayVideoOnclick()
{
Application.runInBackground = true;
StartCoroutine(playVideo());
}
P.S: You can also see my YouTube Video Tutorial and Blog on Playing Videos smoothly in Unity.
It is a well known bug that loading big scenes using LoadSceneAsync may block the gpu completely several seconds (completely unnoticeable in the editor), i´ve also been following this for quite some time now,
From the forums:
https://forum.unity3d.com/threads/starting-async-load-causes-massive-lag-spike.288755/
Official unity Issue tracker:
https://issuetracker.unity3d.com/issues/loading-a-scene-async-creates-huge-performance-spikes-for-the-gpu

Unity canvas scaler hiding animations in high resolution display

I instantiate the following gameObject, which contains an Animator with the mode "always animate" on, the animation goes for 340ms, after that time I destroy the gameObject.
The gameObject Inspector properties:
I instantiate it using the following code:
instancia = (Instantiate(cardAnimation, new Vector3(0, 0, 0), Quaternion.identity) as GameObject).GetComponent<Image>();
instancia.rectTransform.SetParent(transform);
StartCoroutine(KillOnAnimationEnd());
Here is the Coroutine:
private IEnumerator KillOnAnimationEnd()
{
yield return new WaitForSeconds(0.34f);
DestroyImmediate(instancia);
}
Here is how the animation looks like when simulating in Unity (PC-Windows):
But on android after I open the chest it waits 340ms with nothing happening and then show the information above, does this have something to do with the plataform or is some unity or perhaps code related issue?
NOTE: I also have another animation in another scene that is just a already instantiated gameObject in the Hierarchy with always animated on and it works on Android.
--EDIT--
So I have ran the newest version of the app in a emulator which is almost about 1080x480 and the animation showed just as the PC, also running on a 720p smartphone did the job, the only problem I'm still having is with my QuadHD resolution from Galaxy S6, everything else shows but the animation, I have even tried making the animation run without any script so it runs in a loop, but it doesn't show up in galaxy screen.
Given the news about the issue I think this might change a little bit the perspective of answers and perhaps help someone else solve the same problem in the future.
Okay, figured out the problem, its something to do with "rotation" in animations using Unity3D in 2D mode, gonna be reporting it form Unity so it is fixed.
The solution: Animate your UI only using scale/position, if used rotation it will not show on high resolution display.
I am pretty sure your WaitForSeconds(0.34f) is not working properly because there is no thing such as yield keyword in Java. I recommend you to use a invoke method instead to call your method that destroys your GameObject.

Android Front Facing Camera - empty (0km) file or start failed on some devices

I had this problem with my app (ScareApp) that uses the front facing camera to record video. I "think" I've finally resolved the issue, so thought I would post it here for any developers that run into the same thing....
Basically..
The android MediaRecorder allows you to define the Video and Audio Encoder, and according to the docs, DEFAULT can be used for each.
However, this refers to the main camera's settings, which is often a far higher spec than the front facing camera.
DEFAULT on the Droid Razr for example, selects an encoding (MPEG_4_SP) that isn't available for the Front facing camera, and this results in an empty (0kb) file being produced (or on some other devices a Camera 100 - start failed error).
My other option was to use the CameraProfile.get method to lookup what the HIGH_QUALITY settings, but again, this by default uses the main camera.
To get around this, you can set the ID of the front facing camera by using
CameraProfile.get(<CameraID>, CamcorderProfile.QUALITY_HIGH);
My current work around is as follows:
CamcorderProfile profile = CamcorderProfile.get(FrontFacingCameraId, CamcorderProfile.QUALITY_HIGH);
if(profile != null) {
_recorder.setAudioEncoder(profile.audioCodec);
_recorder.setVideoEncoder(profile.videoCodec);
}else {
//default to basic H263 and AMR_NB if profile not found
_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
_recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
}
Or alternatively, you can skip setting the Encoders, and just use
_recorder.setProfile(profile);
But as my app allows the user to select the resolution, I need to set the encoder's.
Hopefully this will help someone and save the time and hassle it has caused me!
Cheers,
Mark

Android Camera.takePicture - Possible to disable shutter sound and preview surface?

I am working on an app that will allow a user to take quick click and forget snapshots. Most of the app is done except for the camera working that way I would like. Right now I have the camera working but I can't seem to find a way to disable the shutter sound and I cant find a way to disable displaying the preview. I was able to cover the preview up with a control but I would rather just not have it displayed if possible.
To sum things up, these are the items that I would like to disable while utilizing the built in Camera controls.
Shutter sound
Camera screen display
Image preview onPictureTaken
Does anyone know of a resource that could point me in the right direction, I would greatly appreciate it. I have been following CommonsWare's example from this sample fairly closely.
Thank you.
This is actually a property in the build.prop of a phone. I'm unsure if its possible to change this. Unless you completely override it and use your own camera code. Using what you can that is available in the SDK.
Take a look at this:
CameraService.cpp
. . .
CameraService::Client::Client(const sp<CameraService>& cameraService,
const sp<ICameraClient>& cameraClient,
const sp<CameraHardwareInterface>& hardware,
int cameraId, int cameraFacing, int clientPid) {
mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
mOrientation = getOrientation(0, mCameraFacing == CAMERA_FACING_FRONT);
mOrientationChanged = false;
cameraService->setCameraBusy(cameraId);
cameraService->loadSound();
LOG1("Client::Client X (pid %d)", callingPid)
}
void CameraService::loadSound() {
Mutex::Autolock lock(mSoundLock);
LOG1("CameraService::loadSound ref=%d", mSoundRef);
if (mSoundRef++) return;
mSoundPlayer[SOUND_SHUTTER] = newMediaPlayer("/system/media/audio/ui/camera_click.ogg");
mSoundPlayer[SOUND_RECORDING] = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg");
}
As can be noted, the click sound is started without your interaction.
This is the service used in the Gingerbread Source code.
The reason they DON'T allow this is because it is illegal is some countries. Only way to achieve what you want is to have a custom ROM.
Update
If what being said here: http://androidforums.com/t-mobile-g1/6371-camera-shutter-sound-effect-off.html
still applies, then you could write a timer that turns off the sound (Silent Mode) for a couple of seconds and then turn it back on each time you take a picture.
You may use the data from the preview callback using a function to save it at a picture on some type of trigger such as a button, using onclick listener. you could compress the image to jpeg or png. In this way, there no shutterCallback to be implemented. and therefore you can play any sound you want or none when taking a picture.
You can effectively hide the preview surface by giving it dimensions of 1p in the xml file (I found an example the said 0p but for some reason that was giving me errors).
It may be illegal to have a silent shutter in some places, but it doesn't appear that the US is such a place, as my HTC One gives me an option to silence it, and in fact, since Android 4.2 you can do this:
Camera.CameraInfo info=new Camera.CameraInfo();
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}

Categories

Resources