I have a problem with video not been playing. I am using SurfaceView with MediaPlayer.
Those are my actions:
MediaPlayer.setDataSource(url)
MediaPlayer.prepareAsync();
MediaPlayer.start() // From setOnPreparedListener listener
MediaPlayer.reset()
Go back to 1 with different url
About 3 out of 5 videos do not start playing. I see nothing in the logs except some times when video does start it show me this:
W/MediaPlayer﹕ info/warning (1, 903)
Can't find 903 in the documentations.
Related
I am using a Videoview to play an animation video in the loop. I noticed that whenever the video is playing if any other music app is playing audio and I click on headset buttons(pause/play), the media button events are not dispatched to the music playing app. Instead, it is dispatched to my ExampleService which extends from MediaBrowserServiceCompat. Videoview is stealing those media button events. I am using even AudioManager.AUDIO_FOCUS_NONE.
I noticed when my app opens and video plays, I can see a log in the stack trace that
D/MediaSessionService: Media button session is changed to com.example.mediasessiontest/ExampleService (userId=0)
Is there a way to play video without requesting for Mediabutton event?
If I don't play video in my app, headset events are correctly routed to the app which was playing music
This is happening only on Android 8 and 9. Works fine on Android 10.
Tried even Surfaceview with Mediaplayer to play video. But observed the same issue.
private val VIDEO_BASE_PATH = "android.resource://"
videoView.setAudioFocusRequest(AudioManager.AUDIOFOCUS_NONE)
videoView.setMediaController(null)
videoView.setVideoPath(VIDEO_BASE_PATH + packageName + "/" + R.raw.test_video)
videoView.setOnPreparedListener { player ->
player.isLooping = true
player.start() //This causes the media button sesssion to be changed
}
Tried using Surfaceview with Mediaplayer as well. But same result. Looks like a bug in OS 8 and 9 ?
I'm desperate, I work with MediaPlayer and I would just pause the player.
But when I try to pause the player, I got error (-38, 0).
And in log : pause called in state 8.
I know this error would mean I try to pause the player when it isn't started. But my code is :
if (mediaMusic.isPlaying()) {
Log.d("GREG", "Media music is playing");
mediaMusic.pause();
Log.e("GREG", "Media music paused");
}
But in logs :
D/GREG: Media music is playing
V/MediaPlayer-JNI: pause
V/MediaPlayer: pause
E/MediaPlayer: pause called in state 8, mPlayer(0x7546266e00)
V/MediaPlayer: message received msg=100, ext1=-38, ext2=0
E/MediaPlayer: error (-38, 0)
V/MediaPlayer: callback application
V/MediaPlayer: back from callback
E/GREG: Media music paused
So if somebody has an idea to resolve this issue it will be beautiful !
Thanks !
EDIT : I've just see the problem is only present when I set the speed of MediaPlayer like that
mediaMusic.setPlaybackParams(mediaMusic.getPlaybackParams().setSpeed(rate));
But I have to change the speed, so the problem is still unsolved ...
I am created an Android app thta needs to have a fullscreen seemless video loop playing in the background. By 'in the background' I mean that there will be buttons on top of the video.
I've read these threadw already
playback video full screen
Integrating video file in android app as app background
but I'm still confused about the following
1 Is the mediaplayer needed for video playback?
2 Will using OnCompletionListener create a 'seamless' loop or will there be a 'hiccup' as the video loops?
Use the setOnPreparedListener to tell the MediaPlayer to loop and start
videoview.setOnPreparedListener(new OnPreparedListener()
{
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.start();
}
});
This is seemless on some devices, but can cause a frame or two of stutter on others :/
App I'm developing contains many short (1-2 sec) videos.
The videos are displayed in one activity. User can either replay video (possibly while video is beeing played) or change actual video.
Part of code changing video:
String videoPath = getVideoPath();
videoView.setVideoPath(videoPath);
videoView.start();
Those 3 lines already causes app to load new video and play it.
Problem starts after video is completed. From this point loading new video causes many problems (Like sometimes for half a movie only sound is played while screen is black blank). There are similar problems with replaying video (which I end up with calling 3 lanes from above).
It seems like android after completing movie releases resources or something like this (and that's why I am settings same path, when I want to replay video).
Ideally I would want video to simply pause and seekTo to beggining of movie after finished playing (but I cannot do this in OnCompletedListener, since it already changed state to stopped...).
Can I somehow achieve this? (By this I mean -> after completed video pauses and seekTo to beginning)
I already tried all combinations of pausing vidoes, suspending them, setting OnPreparedListener, setting OnCompletedListener.
Thx!
Try something like
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer arg0) {
mVideoView.start();
}
});
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.reset();
mVideoView.setVideoPath(file.getAbsolutePath());
mVideoView.start();
}
});
stop the playback, change video path, start video
videoView.stopPlayback();
videoView.setVideoPath(newVideoPath);
videoView.start();
I refactored my code in a following way: Everytime I need new video I reload whole activity. It works most of times, but now instead of video blackness at the beginning of playing I sometimes get "Cannot open media file" error.
Has it something to do with android resource managment? I release mediaPlayer in onCompletionListener.
Has anyone had such problem with playing many videos from external storage?
You can do something like this:
videoView.setOnCompletionListener(MediaPlayer.OnCompletionListener { mp ->
mp.seekTo(0);//go to second 0
mp.start()// start again
})
I discover in this link:
https://developer.android.com/reference/android/media/MediaPlayer
Do this.
videoView.setOnPreparedListener { mp ->
mp.isLooping = true
)
I want to play mp3 radio stream using Android MediaPlayer via http protocol. From time to time [1 playing of 5 - that is actually quite often] I receive PVMFFailure like this:
02-23 02:05:23.503: ERROR/PlayerDriver(91): Command PLAYER_INIT completed with an error or info PVMFFailure
02-23 02:05:23.503: ERROR/MediaPlayer(2111): error (1, -1)
02-23 02:05:23.533: ERROR/MediaPlayer(2111): stop called in state 0
02-23 02:05:23.533: ERROR/MediaPlayer(2111): error (-38, 0)
There is no solution here or on google, so please if you do know how to debug this, please help :)
Here is my code for player:
//start
MediaPlayer player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(address);
player.prepare();
player.start();
//stop
player.stop();
player.reset();
I`m using Android 2.2 API. Thanks!
You should use player.prepareAsync(); instead player.prepare();.