I am a web developer tasked with making what should be a fairly simple app I think. I haven't had much experience with Android development so forgive what may be stupid mistakes.
I basically need to be able to take an array of video paths (that are synced on to the external SD) and play through the videos one by one. I don't need any controls or anything, just fullscreen video.
As I don't have much experience with Android, or Java for that matter, I thought I'd try Easy Video Player, which I guess is just a wrapper for the MediaPlayer class. I can get a single video to play no problem, but I'm having trouble playing the next video automatically. Here's my code so far (Just using online demo videos at the moment rather than off the SD card. Also, the layout file is pretty much the same as the example in the link above, just with a few different attribute values):
public class VideoActivity extends AppCompatActivity implements EasyVideoCallback {
private static final String[] TEST_VIDEOS = {"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4", "http://www.html5videoplayer.net/videos/toystory.mp4"};
private EasyVideoPlayer player;
private int currentVideo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
player = (EasyVideoPlayer) findViewById(R.id.video_player);
player.setCallback(this);
currentVideo = 0;
player.setSource(Uri.parse(TEST_VIDEOS[currentVideo]));
}
@Override
public void onPaused(EasyVideoPlayer player) {
super.onPause();
player.pause();
}
@Override
public void onCompletion(EasyVideoPlayer player) {
if (currentVideo != TEST_VIDEOS.length - 1) {
currentVideo++;
player.reset();
player.setSource(Uri.parse(TEST_VIDEOS[currentVideo]));
player.start();
}
}
}
This is the monitor output that appears when onCompletion()
is called:
D/EasyVideoPlayer: onCompletion()
D/EasyVideoPlayer: Loading web URI: http://www.html5videoplayer.net/videos/toystory.mp4
E/MediaPlayer: start called in state 4
E/MediaPlayer: error (-38, 0)
E/MediaPlayer: Error (-38,0)
I could be nearly there or I could be way off, I just have no idea. I tried calling just player.reset()
in onCompletion()
but it didn't seem to do anything at all. I would assume the player would just go to an initial state with no video loaded.
Any help is appreciated and I apologise for the ignorance,
Thanks.
Update:
I moved player.start();
into an onPrepared()
listener and the errors pasted above no longer appear. Also, after a few seconds, the sound of the next video plays but the player still shows the last frame of the first video with a play button.