Xamarin forms Android SurfaceView - still video image left behind - android

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.

Related

Unity3D VideoPlayer Clip Crashes on Android but Not W10 Desktop

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.

In Quickblox, how can we rotate a video (90 degrees, for example) in Android app (QBRTCSurfaceView)?

We are streaming a video chat using Quickblox and we'd like to be able to rotate it (90, 180, 270 degrees).
In the iOS SDK this seems possible, but with Android there doesn't seem to be a setting. How can we get around this and display the video rotated? Thanks!
You can use a View method : void setRotation (float rotation) like below :
your_vide_view.setRotation(90f);
or
your_vide_view.setRotation(180f);
or
your_vide_view.setRotation(270f);
this method work for sdk >15
you should also add this condition :
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
your_vide_view.setRotation(180f);
}
This may be too late, but for anyone wondering how to rotate the video view, you can get the video track and call addSink() function to retrieve each frame. You can then rotate the frames and call onFrame() function on the videoview. Please find the sample code below.
Remove any renderers before adding the below code and also do not add any renderers because the below code will do that.
localVideoTrack?.track?.addSink { videoFrame->
localVideoView.onFrame(VideoFrame(videoFrame.buffer, 90, -1))
}

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

QBGLVideoView rotated when called getCurrentSession().switchCapturePosition(null)

I am working on Quickblox videochat. Everything works good, but the time I want to switch the camera i.e from front cam to the back cam by calling:
if (getCurrentSession() != null)
getCurrentSession().switchCapturePosition(null);
It successfully switch the camera, but on the other side, i.e. on remote videoview of opponent, the view comes 180 degree rotated.
And moreover the local videoview is also rotated. I tried using:
local_ongoing_call.setVideoViewOrientation(-90);
but, it rotates the view at my end, whereas the opponent is still having the same rotated view. Need help!
You can rotate QBGLVideoView on opponent’s side. Seems like this issue is related to particular devices and webrtc library version.
There should be new video calls released in the nearest future, so most probably the problem will be solved with the new version.

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