Unity VideoPlayer and WebGLMovieTexture cant play two videos in a row - unity3d

I'm trying to play videos in Unity WebGL in the browser, but having lots of problems.
I tried two different video players and none of them work fully.
The WebGLMovieTexture player works like this
public WebGLStreamingVideoPlugin _videoPlugin = new WebGLStreamingVideoPlugin("http://www.example.net/video.mp4");
_videoPlugin.Play();
Basically when you want to play a video you create a new instance and give it the URL like above, and it plays great!!
The problem is when you want to stop that video, and play a different video, it seems impossible because there is no way dispose of the first video because there is only a Stop() in the API, which stops the playback but it continues to stream the video data from the internet in the background.
There is no way to delete the instance because Destroy() cant be called since that WebGLMovieTexture is not derived from monodevelop, and C# does not seem to give a way to delete an object (how silly). Even setting it to null doesnt do it, it continues to stream the video in the background.
So if you create a new instance in order to play a different video, you end up with TWO video streams, and if you do it again to play a third, you end up with THREE, and so on, so quickly you can see how bad that will end up.
My question is how to dispose of or destroy the first WebGLMovieTexture player, or maybe tell it to stop streaming the first video and start playing a different one?
The second player I tried is the VideoPlayer for WebGL in Unity Version 5.6.0b4, with this one I can only get it to play a video if I hardcode the URL in the inspector, if I put the URL in code it doesn't play it in the browser.
vPlayer = gameObject.GetComponent<UnityEngine.Video.VideoPlayer>();
if (vPlayer.isPlaying) {
Debug.Log("STOPPING PLAY");
vPlayer.Stop();
}
vPlayer.url = url;
vPlayer.isLooping = true;
vPlayer.frame = 0;
vPlayer.targetCameraAlpha = 1F;
vPlayer.Prepare();
vPlayer.Play();
And to get it to play a second video I suspect I will have the same problems as the other one.
Anybody have any ideas that can help me?

Related

Playing same audio on two players simultaneously using just_audio and just_audio_background

I am working on an app that plays audiobooks, and when you click a book in your list a full window player will start playing the book, however when you close/minimize it, I want a miniplayer to show right about the navbar in the bottom. This player has to continue playing from where the first player "stopped" until the user decides to pause.
Im unsure if this can be achieved without having to have both play the audio at the same time? Reason is that when the Fullscreen is closed, player.Dispose is called.
I currently have a function which saves the position of the player and stores it in shared pref, it however cuts the seconds of, so even if I called that in the miniplayer, it wouldnt continue from the same position.
Im new to flutter/dart btw, with only a few months experience. Thanks in advance
You should use a single player and then have two player "widgets" displaying the state of that same player. That way, you don't need to try to stop and start the player - the player can continue playing the whole time while the widgets are the only things changing.
If you're a beginner, the simplest way to define a single player that can be referenced from everywhere is to define it in a global variable, outside of any class declarations (for something more advanced, read about the service locator pattern):
final player = AudioPlayer();
Then let's say you have two widgets to view the state of the same player: FullPlayerWidget and MiniPlayerWidget. They can both reference the same player instance defined above.
Finally, your logic error is that you are calling dispose when minimising the full player widget. You shouldn't do that unless you want the audiobook to stop playing permanently. You don't want it to stop permanently, and you don't even want it to stop at all!
Actually, the only thing you want to happen when minimising is a visual thing. You want to hide the full widget and display the mini widget. But on the audio side, you want the player itself to be unaffected, continuing to play audio as if nothing had happened. Therefore, in this event you should in fact not call any methods on the player.
The best thing you can do as a beginner is to study lots of examples. E.g. podcastproject (although its dependencies are a bit out of date now).

Unity Video Player, the video cannot be played properly

I am developing a game for android and ios via Unity. I have to play a video in a scene in the game and I use the video player component for this. I get the video link on local using xampp. And the video I'm trying to play is in mp4 format. But when I start the game, the video cannot be played properly. I am not getting an error, but video looks like the picture I send. I don't know what I'm doing wrong, can you help me? I also share the code I used and related pictures with you.
public VideoPlayer videoplayer;
public string videoUrl="urlgir";
void Start() {
videoplayer.url = videoUrl;
videoplayer.audioOutputMode=VideoAudioOutputMode.AudioSource;
videoplayer.EnableAudioTrack (0, true);
videoplayer.Prepare (); }
I think I found something. I uploaded the video I mentioned to unity again. I got a warning after uploading the video.
VFR warning: 1111 video frames have a different duration than expected 0.0333333s, ranging from 0s to 1.2771s.D:/Program Files/Unity/xxx/Assets/Scenes/hp.mp4 (30FPS) may have variable frame rate (VFR), which is not supported. This may lead to incorrect timing in transcoded clip.
I think the video has unsupported variable frame rate. So I can't run the video as clib or url. Well, does anyone know of this warning? What should be needed?

Is there a way to start buffering video before playing it in Flutter?

I am trying to make an app that can play multiple videos at once. The goal is to record multiple music voices and then play them together. I am using the video_player plugin and each video has its own player. The problem is that when I start playing, it is not reliable when each player will start. So, I thought if I load the files before start playing this difference could be reduced. But I couldn't figure out how to do it and if it is possible to do. So, is there a way to load those files to reduce this difference? If there is another way to achieve my goal I would be glad to know. Thank you!
I have a similar problem where I want to control the exact moment the video starts playing.
For now, the best way seems to be (assuming you have a _controller constructed already)
await _controller.initialize()
await _controller.play()
await _controller.pause()
After that, the video starts playing almost immediately. For my purposes it’s good enough but if you need to control this down to the millisecond for synchronization purposes it might not cut it.
You might also want to hide the video and mute it during those first calls.

How to use vuforia in unity with sound

I have a problem using vuforia with unity, I have 10 videos in database and when I start the App the sound from the videos start playing immediately even if there is no cards to read from.
Check you AudioSource components are on the target object, so it gets disabled.
If this happens and you still have the problem, add custom code so that it gets muted on OnTrackingLost and unmute in OnTrackingFound.
The class you are looking for id DefaulTrackableEventHandler, you can inherit from that one and add that code instead to our target using overrides or add code there like GetComponent.

add more than 1 video player in iphone

Is there any way to add more than 1 video player in a single View? I am getting the .m4v list from server adn have to display that much videos in single page.
It doesnot matter if I play 1 video at a time but which ever video I want must play there itself.
So the videos are placed one below other.
I have tried using mpmoviecontroller but it's drawback is it can have only one instance in the whole applicaiton So if i try to alloc 2 players in a view then the first one does not work and only one player works..
Is there any legal alternate way for the same?
MPMoviePlayerController will allow multiple instances, but only one of them can be playing their movie at any given time.
Please check the link : http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
I used AVPlayer class (which also MPMoviePlayerController uses under the hood) to successfully play multiple videos from multiple source.
The process of using it is more involved than MPMoviePlayerController, but I would say it is definitely worth to look at if you want some customized behavior in your player. The official programming guide is a good start.