I have a video playing using the VideoView control,
VideoView vid;
vid = (VideoView)findViewById(R.id.video);
String urlpath = "android.resource://" + getPackageName() + "/" + R.raw.videoviewdemo;
vid.setVideoURI(Uri.parse(urlpath));
vid.start();
which works fine, but I assumed incorrectly that calling setVideoURI() and start() would wait for the first video to finish before playing the second. Is there any way to make the entire video play before moving on to the next line of code? Thanks
(I just started Android/Java programming a few days ago, and haven't written software in ANY language for years, so forgive me if I'm a little slow)
you can always use the completion listener to play the next video.
it will trigger as soon as current video gets finished.
keep track of the currently running video in the global integer.
update it to keep the track of them and get the next video to play
check this link
Listener (or handler) for video finish
Related
I currently can stream audio using an html 5 object, short snippet of code below.
let snd = new Audio("data:audio/wav;base64," + this.hexToBase64(this.waveHeader + this.byteStream));
snd.play();
Unfortunately I am encountering this error and I have made a post found at STREAM- DOMException: play() can only be initiated by a user gesture
`this.byteStream` is a buffered 0.1 (s) of audio data in hex
So far, I reconstruct a new file each time I want to play 0.1 (s) of audio stream, so I thought how is this really streaming? Wouldn't the best approach to this be somehow to create an audio object once give it a wave header + initial data and somehow tell the audio object, for each new data appended continously play it. So I hit .play() once, and each time I append data it plays it. This would put the buffer responsibility on the API.
That would be so nice, is this possible? This would also fix my problem as the .play() method is only called once
Update : I decided to add an event, such that when you click anywhere the code is ran.
<div id="container" [style.background]="getContainerStyle()" (click) = "start()">
start(), ran my program like normal before encapsulated inside the event. Still did not work.
In my app, I have to play many sounds (mp3 files downloaded and stored on SD Card) one after the other.
So I used a basic MediaPlayer and I set setOnCompletionListener method to continue playing next media file:
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(PATH + Constants.Medias.PATH + SLASH + (pref + 1) + SLASH + AppUtils.format(suffix + 1) + AppUtils.format(currentMediaFile));
My big problem is that there is GAP when switching from a file to the next one... It make a strange noise that disturbs users.
Have you any idea how to play these files as if they are "one track" (continuously).
You can try to create two instances of MediaPlayer (let's call them M1 and M2).
M1 starts to play the first file (F1)
while M1 is playing, M2 starts preparing for F2 (onlyprepare() is called)
when M1 finish, its OnCompletionListener triggers M2 which starts to play
continue inverting M1 with M2 until all files have been played.
If this doesn't work and you still hear noise try to use SoundPool instead of MediaPlayer.
I am working with streaming video and I want to change from one source to another dinamically.
First I set the video uri to the VideoView
view.setVideoURI(myUri);
And I know that I am capable of changing it afterwards by doing (this is in onPrepare method but it could go somewhere else where I have access to the MediaPlayer).
#Override
public void onPrepared(MediaPlayer mp)
{
Uri newUri = getOtherUri();
mp.reset();
mp.setDataSource(getApplicationContext(), newUri);
mp.prepare();
mp.start();
}
The thing is, I want to change the source without reseting the mediaPlayer (I do not want to disturb the user).
I tried to create a new VideoView with the new Uri and then change one object for the other, and likewise with the media player. However, none of that seems to work.
Is it possible to replace a video while it is playing in Android?
Any comments would be appreciated.
There is no option to reset the video without using mediaplayer.stopPlayback() or mediaplayer.reset. The reason is that; the previous object of the mediaplayer has to be released before you can play other video .
I want to change the source without reseting the mediaPlayer (I do not want to disturb the user).
Well, this cannot be achieved as the mediaplayer has to be reset. So there will be lag while changing videos. And to satisfy you, you can see these behavior in any videoplayer app like youtube or mxplayer.
So the only thing you can do is to show progressbar while loading or changing video.
Hope it helps. Cheeers.:)
I'm building an interactive movie of some sort , having more video clips that need to load between interactive scenes. The problem is there is a slight delay when starting the video which I believe it could be fixed by preloading the clip right before the previous one finishes. I've tried to start() the video and then stop() it, also seekTo() but i'm no getting the desired result.
Also I need to mention I'm using several VideoViews in the same Activity so I display the appropriate one.
The video files are loaded from the raw folder using the following code
videoView1 = new VideoView(this);
mediaController1= new MediaController(this);
mediaController1.setMediaPlayer(videoView1);
mediaController1.setVisibility(View.INVISIBLE);
Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sa1);
videoView1.setMediaController(mediaController1);
videoView1.setVideoURI(uri);
videoView1.requestFocus();
videoView1.start();
Thank you.
You can handle the loading in another thread with using, for example, AsyncTask while the user watches the pervious video.
http://developer.android.com/reference/android/os/AsyncTask.html
I am having problems with multiple videoViews specifically on Galaxy Tab.
In my app, I have two different video files which I want to play simultaneously. So I designed my app to have two videoViews side by side. Tried to run it on two non Galaxy tabs and it worked. Easy as that.
But then, I tried to test it on my Galaxy Tab and the problem comes out. The two video file doesn't play. At some point, the first video file plays and then stops and pops up the Cannot Play Video error. I spent almost two days looking for the cause of the problem and I failed. That's why I resorted to guessing what could be the cause.
My suspicion was that it cannot render two videos at the same time, so I tried to play only the sound of the first file using MediaPlayer and play the other one in the videoView. And I think my suspicioin was right because it works, the first video file plays only the sound, and the other one plays the full video and the sound.
I am looking for someone with this kind of problem, or someone who knows a workaround for this. I will post my simple code here for you to take a look at it. I would really appreciate your help! Thanks in advance.
junmats.
final videoView v1 = (VideoView) findViewById(R.id.videoView1);
final videoView v2 = (VideoView) findViewById(R.id.videoView2);
Thread th1 = new Thread(new Runnable() {
#Override
public void run() {
Uri uriFile = Uri.parse(myFile);
v1.setVideoURI(uriFile);
v1.start();
}
});
th1.start();
Thread th2 = new Thread(new Runnable() {
#Override
public void run() {
Uri uriFile = Uri.parse(
v2.setVideoURI(uriFile);
v2.start();
}
});
th2.start();
This seems to be dependent on the kernel version so it may not be supported on certain devices... http://code.google.com/p/android/issues/detail?id=17802
You may have to wait for an update.