Android-ScalableVideoView icon indicating copy to clipboard operation
Android-ScalableVideoView copied to clipboard

MediaPlayer initialization

Open 4eRTuk opened this issue 8 years ago • 3 comments

I think MediaPlayer should be initialized in constructor (not in setDataSource like now) because start/stop/pause etc. methods throw NullPointerException if data source hasn't been set yet.

4eRTuk avatar Aug 27 '15 10:08 4eRTuk

I'll second this for another reason.. I have a ScalableVideoView inside of a fragment, and a helper class that downloads a list of videos to play them consecutively as soon as one has been downloaded (Sort of like snapchat). If the MediaPlayer isn't initialized in onCreateView, the videos will play with audio, but no video. I worked around this by subclassing ScalableVideoView and creating my own method to initialize MediaPlayer, but would have saved a lot of headache if it were initialized in the constructor.

paulblakely avatar Sep 14 '15 10:09 paulblakely

@paulblakely ok, I'd love to see it if you can send me Pull Request

yqritc avatar Sep 14 '15 11:09 yqritc

I solved this by the following code:

mScalableVideoView = (ScalableVideoView) findViewById(R.id.video_view);
try {
    mScalableVideoView.setDataSource("");
} catch (IOException e) {
    e.printStackTrace();
}

szitguy avatar Oct 13 '15 09:10 szitguy