Have the source code VLC.
Compiled under android.
Added activity.
It has three buttons.
at the touch of a button should switch the channel stream , video from sd card or video from internet.
public void onClick(View v)
{
switch (v.getId()) {
case R.id.b1:
break;
case R.id.b2:
break;
case R.id.b3:
Context context = this;
VideoPlayerActivity.start(context, "http://www.youtube.com/watch?v=9Xjw2PtKjJE",
null, false, false);
break;
}
All compiled. By clicking the button, a player, but the video does not start to play.
Blank screen and the player does not see the video.
The same problem with the video playback from the card.
Tell me how to handle the press of a button.
Sorry for my English.
Instead of VideoPlayerActivity.start
VLCCallbackTask task = new VLCCallbackTask(MainActivity.this)
{
#Override
public void run() {
AudioServiceController c = AudioServiceController.getInstance();
c.append("http://www.youtube.com/watch?v=9Xjw2PtKjJE");
}
};
task.execute();
Related
I used libvlc (de.mrmaffen:vlc-android-sdk:1.0.6) library for http video streaming. Everything works fine just one issue.
I used progress-bar before my playmovie() function call,and stop the progress-bar with using libvlc.isPlaying() boolean function so at this time my guess is video is loaded and we will stop the progressbar.
How to get exact time for buffering the video and streaming start to stop the progressbar?
You need to implement EventListener.Like this way
LibVLC vlcInstance = new LibVLC(context, new VlcOptions().getDefaultOptions());
org.videolan.libvlc.MediaPlayer player = new org.videolan.libvlc.MediaPlayer(vlcInstance);
player.setEventListener(new org.videolan.libvlc.MediaPlayer.EventListener() {
#Override
public void onEvent(org.videolan.libvlc.MediaPlayer.Event event) {
switch (event.type) {
case org.videolan.libvlc.MediaPlayer.Event.Opening:
//Video Opening
break;
case org.videolan.libvlc.MediaPlayer.Event.Playing:
//Video Playing
break;
case org.videolan.libvlc.MediaPlayer.Event.Buffering:
//Video Buffering
break;
case org.videolan.libvlc.MediaPlayer.Event.Stopped:
//Video Stopped
break;
case org.videolan.libvlc.MediaPlayer.Event.EndReached:
//Video EndReached/Completed
break;
case org.videolan.libvlc.MediaPlayer.Event.EncounteredError:
//Video EncounteredError/Failed
break;
default:
break;
}
}
});
Media media = new Media(vlcInstance, videoUri);
media.addOption(":fullscreen");
media.setHWDecoderEnabled(true, false);
player.setMedia(media);
IVLCVout vlcOut = player.getVLCVout();
on clicking the play button if music is playing the music should pause and image of button should change to pause button and vice versa
I dont know whats wrong with the logic please check.
public void onClick(View v) {
switch (v.getId())
{
case R.id.mpPlay: // bPlay
if(!mediaPlayer.isPlaying())
{
mediaPlayer.start();
bPlay.setBackgroundResource(R.drawable.play);
}
if(mediaPlayer.isPlaying())
{
mediaPlayer.pause();
bPlay.setBackgroundResource(R.drawable.pause);
}
break;
}
Try to use
setImageResource(id);
or
setImageDrawable(ContextCompat.getDrawable(context, id));
You should replace your second "if" statement with an "else". When your code is executed, the media player is not playing so your first "if" statement gets executed. This turns on your media playback. However, when your code gets to your second "if" statement, your media will be playing, so it immediately turns back off. Replacing your second "if" statement with an "else" will ensure that only one of the options (turn media playback on or turn media playback off) will be executed on any given onClick().
if(!mediaPlayer.isPlaying())
{
mediaPlayer.start();
bPlay.setBackgroundResource(R.drawable.play);
}
else
{
mediaPlayer.pause();
bPlay.setBackgroundResource(R.drawable.pause);
}
As I understood
ImageButton bPlay = (ImageButton)findViewById(R.id.mpPlay);
//mpPlay is id of your ImageButton for play button in xml file
is Ok.
So, try this:
public void onClick(View v){
switch (v.getId()){
case R.id.mpPlay:
if(!mediaPlayer.isPlaying()){
mediaPlayer.start();
bPlay.setImageResource(R.drawable.pause);
//pause icon during player plaing
} else if(mediaPlayer.isPlaying()){
mediaPlayer.pause();
bPlay.setImageResource(R.drawable.play);
//play icon during player on pause
}
break;
}
}
In some way, it's logically
I am having trouble with MediaPlayer. In the enclosed code, when a button is touched, a voice cue is activated when the option to do so is selected. However, the voice works for approximately 31 times and then the sound goes off. Using the .release() method (which I have commented out for now) causes the sound to not work at all.
How can I correct this function?
Thank You
....
import android.media.MediaPlayer;
....
MediaPlayer mp = null;
........
// Causes the name of the appropriate cell to be announced
public void sayCellName() {
if(voiceChoice == false) return;
else{
switch(cellName){
case 1:
mp = MediaPlayer.create(this, R.raw.poly);
break;
case 2:
mp = MediaPlayer.create(this, R.raw.lymph);
break;
case 3:
mp = MediaPlayer.create(this, R.raw.mono);
break;
case 4:
mp = MediaPlayer.create(this, R.raw.eo);
break;
case 5:
mp = MediaPlayer.create(this, R.raw.baso);
break;
case 6:
mp = MediaPlayer.create(this, R.raw.band);
break;
default:
break;
} // end switch statement
} // end else statement;
mp.start();
// mp.release();
} // end of sayCellName
} // end of main
The Android OS has a hard-coded limit of audio track resources that may play back sound simultaneously. As it so happens that limit is 32 tracks that have to be shared by all running applications. What you are doing is wasting these tracks by creating fresh MediaPlayers on each button click without releasing them.
For your scenario you should probably create and reuse a single MediaPlayer instance and release it when your Activity stops. It is possible to reset a MediaPlayer and set a different stream data source afterwards.
You have to release the player OnPause or OnDestroy method.
#Override
public void onPause() {
if (mp!= null) mp.release();
}
I have the following code snippet. Not sure why, when clicked on the exit button the media player doesn't stop, even though exiting the game should stop all activities in it.
Any help would be appreciated.I have tried stop(), release(), reset() and setting to null. Please let me know where am I going wrong.
public void onClick(View v){
// The background music of the game
MediaPlayer back_music = MediaPlayer.create(getBaseContext(), R.raw.sher_khan);
switch (v.getId()){
case R.id.new_game:
openNewGameDialog();
break;
case R.id.about_game :
Intent i = new Intent(this, About.class);
startActivity(i);
break;
case R.id.exit_game :
if(back_music.isPlaying()){
back_music.release();
back_music.reset();
back_music = null ;
//onDestroy();
}
finish();
break;
case R.id.sound :
// Looping the music
//back_music.setLooping(true);
// Identifying and kind of looping through the sound_selector items
if(v.isSelected()){
v.setSelected(false);
play = false;
//Music start for the media player
back_music.start();
}
else if (!v.isSelected()){
//speaker.setSelected(false);
back_music.stop();
back_music.release();
v.setSelected(true);
play = true;
back_music.release();
}
}
Please try the following :
create your media player on the on create and declare it as a member of your ACTIVITY :
MediaPlayer back_music;
public class MainACtivity(){
....
....
onCreate(){
back_music= MediaPlayer.create(getBaseContext(), R.raw.sher_khan);
.....
}
then delete the the row "MediaPlayer back_music = MediaPlayer.create(getBaseContext(), R.raw.sher_khan);"
and give it a another shot :)
hope it helps you .
I'm creating a sampler app for school. I've wrote code which plays a sample when I press and hold a button and stops when I release it. My problem is that it has too much latency. It takes too long after I press the button to play the sound.
My audio files are mp3's.
Here's my code:
smpl1.setOnTouchListener(new View.OnTouchListener()
{
public boolean onTouch(View arg0, MotionEvent theMotion)
{
switch (theMotion.getAction())
{
case MotionEvent.ACTION_DOWN:
sample = MediaPlayer.create(MainActivity.this, R.raw.bassdrum);
smpl1.setText("ON");
smpl1.setTextColor(Color.GREEN);
sample.start();
break;
case MotionEvent.ACTION_UP:
smpl1.setText("OFF");
smpl1.setTextColor(Color.RED);
sample.stop();
break;
}
return true;
}
Create the sample object before the button press, then just use the start / stop functionality in your handler code.