Android MediaPlayer freezes after seeking a new video position - android

I load a .mp4 on a VideoView, all things go fine until I drag the seekbar point to a new position, so the MediaPlayer starts to buffering and then the app freezes (not crash, just freeze) with an error message:
"Can't play video"
This is the code:
try {
// Start the MediaController
controller.setAnchorView(videoView);
// Get the URL from String VideoURL
Uri video = Uri.parse(getIntent().getExtras().getString("video"));
videoView.setMediaController(controller);
videoView.setVideoURI(video);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
pDialog.dismiss();
videoView.start();
}
});
No errors if I seek an already-buffered position. Only with no-buffered positions.
Error log:
Attempt to perform seekTo in wrong state: mPlayer=0x5c149090, mCurrentState=0
E/MediaPlayer(17339): error (1, -110)
E/MediaPlayer(17339): Error (1,-110)
D/VideoView(17339): Error: 1,-110

Related

Video view displaying the can't play dialog in android

I am displaying the videos in a list. After playing the videos one after another it is displaying video can't play error in android naught only in Remaining all the versions are working fine.Please help me to resolve this issue. Below is the my code for playing the video in video view.
videoview.setVideoURI(Uri.parse(streamInfo.video_streams.get(0).url));
viewHolder.large_videoview.seekTo(starttime * 1000);
viewHolder.large_videoview.start();
videoview.setOnPreparedListener(new OnPreparedListener() {
// Close the progress bar and play the video
public void onPrepared(MediaPlayer mp) {
mMediaPlayer = mp;
mp.setOnInfoListener(new MediaPlayer.OnInfoListener() {
#Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
Log.e("large_videoview", "<><>onInfo");
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START)
//Log.e("buffering starts", "buffering starts");
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END)
Log.e("buffering ends", "<><>buffering ends");
return false;
}
});
}
});
getting this error in my log cat
E/MediaPlayer: invoke failed: wrong state 0, mPlayer(0x7a30b0e0)
E/MediaPlayer: Error (1,-19)
E/MediaPlayer: Error (1,-1010)
Are you sure you are doing like this?
videoview.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoview.start();
}
});
i.e wait for VideoView to be prepared & once it's prepared, you call start() on it?

Radio stream issue

Hi we have an app in the playstore that has a module that play a stream from an url, the app works fine and we make a yearly release, but now that we are making changes, the part of the radio does not work, in any device.
Basically my code is
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource("http://radio.promosat.com:8104/");
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
mediaPlayer.prepareAsync();
}catch (Exception ex){
ex.printStackTrace();
}
I keep getting this error
E/MediaPlayer: Error (1,-2147483648)
This worked perfectly, the url that we use it's in the example code, it uses a pls file, that's where we obtained the stream url.
The error was the encoding of the stream...aacp is not supported in Android.

play 2 videoview overlap in one layout

I want to make 2 videoviews overlap in one layout like this
This my code:
private void PlayVideo() {
try {
getWindow().setFormat(PixelFormat.TRANSLUCENT);
MediaController mediaController = new MediaController(
MainActivity.this);
mediaController.setAnchorView(videoView);
Uri video = Uri.parse(videourl);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
// videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
} catch (Exception e) {
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
.create();
// Setting Dialog Title
alertDialog.setTitle("Alert Dialog");
// Setting Dialog Message
alertDialog.setMessage("Video Play Error :" + e.toString());
progressDialog.dismiss();
System.out.println("Video Play Error :" + e.toString());
finish();
}
My problem is: video 1 can play, but video 2 not play. If I minimize my application and I maximize again, 2 videos can run at the same time.
Please help , thanks before!
VideView is a surface view that should not overlay each other. The order of the components in the layout is not considered during rendering. The solution is to use the setZOrderMediaOverlay() method to inform the system that video2 is above any other surface. In your code I can't see video2 but you should include the following line in its initialization.
video2View.setZOrderMediaOverlay(true);

android play sound from sd-card

I need to play sound from sd card. I have method that must do this but it's doesn't work.
When I use this method:
public class AudioPlayService extends Service
{
MediaPlayer mMediaPlayer;
..............
public void soundplay(String adr)
{
mMediaPlayer = new MediaPlayer();
try
{
if (mMediaPlayer.isPlaying())
{
mMediaPlayer.reset();
}
mMediaPlayer.setDataSource(adr);
mMediaPlayer.prepare();
} catch (IOException e)
{
}
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(new OnCompletionListener()
{
#Override
public void onCompletion(MediaPlayer mp)
{
mp.release();
mp = null;
}
});
}
Where String adr - it's absolute path to file on sd.
Then I call it:
AudioPlayService s = new AudioPlayService();
s.soundplay(iA.getSdDir() + "Files/Numbers/0.mp3");
and I get an err's:
12-09 13:04:13.829: E/MediaPlayer(16997): error (1, -2147483648)
12-09 13:04:13.829: E/MediaPlayer(16997): start called in state 0
12-09 13:04:13.829: E/MediaPlayer(16997): error (-38, 0)
12-09 13:04:13.839: E/MediaPlayer(16997): Error (-38,0)
I myself tried your code:
Mine worked fine when i put just "sdcard/1.mp3"
You ensure that the path is right or not
s.soundplay(iA.getSdDir() + "Files/Numbers/0.mp3");
Note:
If you are trying to make your method soundplay so as to stop previous audio and play the new audio file, then better would be not to perfom this inside that method
mMediaPlayer = new MediaPlayer();
Place this in constructor.
Otherwise each time you invoke s.soundplay(path) you will hear previous audio plus the new audio. ie,Previous one will not be stopped
player.start() put within try,catch block. Because if player not prepare your song ,still you are calling start method.start method is only called after playback is ready,
means prepare is success.Another thing is that you have to release the media player when your player is no longer.Otherwise there is so many player objects are running in back ground.
For some reason, your setDataSource() or Prepare() is failing. So after the exception, start()is giving the error, since the player is not in Prepared state. Add print statements in the catch block to know what is the exception. And move start() into the try catch block.
mMediaPlayer = new MediaPlayer();
try
{
if (mMediaPlayer.isPlaying())
{
mMediaPlayer.reset();
}
mMediaPlayer.setDataSource(adr);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e)
{
e.printStackTrace();
}

Strange behaviour with mediaplayer and seekTo

I'm implementing a custom video player because I need custom video controls. I have an app with only one activity, which on startup shall start playing a video right away.
Now, the problem I have is:
I don't want the video to start from the beginning, but from a later position. Therefore I do a seekTo(16867). Since seekTo is asynchronous, I place the start call of the mediaplayer (player.start()) in the onSeekComplete of the onSeekCompleteListener.
The strange behaviour I experience though is that I can see/hear the video playing from the beginning for a few millisecs before it actually plays from/jumps to the position I seeked to.
But - on the other hand - the Log output I call before the player.start returns the correct position 16867, where I seeked to.
Below is the relevant code section, the complete class is at http://pastebin.com/jqAAFsuX
(I'm on Nexus One / 2.2 StageFright)
private void playVideo(String url) {
try {
btnVideoPause.setEnabled(false);
if (player==null) {
player=new MediaPlayer();
player.setScreenOnWhilePlaying(true);
}
else {
player.stop();
player.reset();
}
url = "/sdcard/myapp/main/videos/main.mp4"; // <--- just for test purposes hardcoded here now
player.setDataSource(url);
player.setDisplay(holder);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setOnCompletionListener(this);
player.setOnPreparedListener(this);
player.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
public void onSeekComplete(MediaPlayer mediaPlayer) {
Log.d("APP", "current pos... "+ player.getCurrentPosition() );
player.start(); // <------------------ start video on seek completed
player.setOnSeekCompleteListener(null);
}
});
player.prepareAsync();
}
catch (Throwable t) {
Log.e(TAG, "Exception in btnVideoPause prep", t);
}
}
public void onPrepared(MediaPlayer mediaplayer) {
width=player.getVideoWidth();
height=player.getVideoHeight();
if (width!=0 && height!=0) {
holder.setFixedSize(width, height);
progressBar.setProgress(0);
progressBar.setMax(player.getDuration());
player.seekTo(16867); // <------------------ seeking to position
}
btnVideoPause.setEnabled(true);
}
Since I also haven't recieved any reply from the Android developer list and found similar issues on the web, I conclude it's a bug. I filed a bug report at http://code.google.com/p/android/issues/detail?id=9135

Categories

Resources