Change media volumn while play music - android

I use below call to play music:
vv = (VideoView)findViewById(R.id.screen_audio);
Uri music = Uri.parse(path);
vv.setVideoURI(music);
vv.start();
But when I playing, the volumn_up and volumn_down button can not press.
How can modify it to change the media volumn?

You have to use controls to change the volume. Check below example to know about it.
Implement a SeekBar to control the volume of Video Player

Related

how to play music on click of an action button

i am trying to play music or mp3 on click of an action button but none is working since most of the tutorials are based on button listeners. i need help regarding how to play music on click of an option menu or action bar menu. Can anyone please help me regarding this problem.
Here is a recommended solution to playing a mp3:
Link: Simple mediaplayer play mp3 from file path?
String filePath =
Environment.getExternalStorageDirectory()+"/yourfolderNAme/yopurfile.mp3";
mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare();
mediaPlayer.start()
and this play from raw folder.
int resID=myContext.getResources().getIdentifier(playSoundName,"raw",myContext.getPackageName());
MediaPlayer mediaPlayer = MediaPlayer.create(myContext,resID);
mediaPlayer.prepare();
mediaPlayer.start();

One media controller for two video views android

I am trying to play two video views using the same media controller but it seems impossible to play them and stop them and seek through both at the same time
can someone suggest a solution here is what I am trying :
//2 video views
videoview=(VideoView)findviewbyid(R.id.videowview);
videoviewtwo=(VideoView)findviewbyid(R.id.videowview2);
//the media controller
MediaController mc =new MediaController(this);
//setting uri for both:
videoview.setVideoURI(uri);
videoviewtwo.setVideoURI(uri1);
//setting same media controller object for both
videoview.setMediaController(mc);
videoviewtwo.setMediaController(mc);
//finally start both
videoview.Start();
videoviewtwo.Start();
after this both play well at the first time but when I try to repeat only one starts the other doesnt, thank you for your help.
Edit: I want them both to play at the same time each time I repeat the process .
You need to release and set the mediaplayer to null before you can start the new video. Try to call this when the video has stopped and before you start a new video so you know that the mediaplayer is not busy.
private void releaseMediaPlayer() {
mMediaPlayer.release();
mMediaPlayer = null;
}
So next is to find out when the mediaplayer have stopped playing your video. A hint: MediaPlayer.OnCompletionListener

I cannot change a video using MediaPlayer without reseting

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.:)

Event on start play remote mp3 in MediaPlayer

I set in MediaPlayer source as url with remote mp3 file. I want listen, where start playing song.
At start some time need to download mp3 header (caching) and only after start playing song. How I can know about this moment? I know only simple way: check at timer isPlaying status...
If you use Android native MediaPlayer, there's an event called onPrepare which is called when the mediaplayer is ready to play your music
For example how to catch the above event on VideoView.
video = new VideoView(activity);
video.setOnPreparedListener(new OnPreparedListener() {
}

Android play a video with controller

I'm using the following code to play a .mp4 video on my android device. I have 3 problems,
using this code when I press the back button on the device the sound would still continoue to play
It doesn't play the video, only plays the sound!
I don't know how to get controller for the video so the user can stop the video, go back or forth on the video.
VideoView videoHolder = new VideoView(this);
videoHolder.setMediaController(new MediaController(this));
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaPlayer mediaPlayer = new MediaPlayer();
Uri myUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.video);
videoHolder.setVideoURI(myUri);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
videoHolder.requestFocus();
videoHolder.start();
1) Override onBackPressed in your activity:
#Override
public void onBackPressed() {
mediaPlayer.stopPlayback();
super.onBackPressed();
}
2) Is it a valid video format? Are you using emulator or a real device? If you use an emulator, try a real device instead. I recall similar issues before.
But I also notice: did you put your video in the drawable folder?
R.drawable.video
I don't think that will work, you cannot play videos from there. Use the resources/raw folder instead. btw: Audio can be played from assets folder directly, while video cannot; video can only played from the raw folder or if you copy it to the apps files folder (getFilesDir()) - or sdcard of course.
3) Why are you using a VideoView AND a MediaPlayer, instead of just a VideoView? You should get rid of the mediaPlayer and just use the VideoView. This line
videoHolder.setMediaController(new MediaController(this));
looks correct and sets the media controller, with which the user can seek in the video.
Programatically you can also use seekTo() to go back and forth in a video.
VideoView videoView =(VideoView)findViewById(R.id.vv01);
//specify the location of media file
Uri myUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.login_footage);
//Setting MediaController and URI, then starting the videoView
videoView.setVideoURI(myUri);
videoView.requestFocus();
videoView.start();
This worked for me

Categories

Resources