I am having two buttons and two songs. Button 1 initializes and plays song 1. Same with button 2 and song 2.
So, on click, button 1 uses create
, setDataSource
, prepare
and start method
.
So, what's the difference between the reset and the release method?
Should button 2 use reset
, create
, setDataSource
, prepare
and start
OR release
, create
, setDataSource
, prepare
and then start
?
For my testings, it's the exact same...
From the API docs (which I strongly recommend you read):
release():
Releases resources associated with this MediaPlayer object. It is considered good practice to call this method when you're done using the MediaPlayer. In particular, whenever an Activity of an application is paused (its onPause() method is called), or stopped (its onStop() method is called), this method should be invoked to release the MediaPlayer object, unless the application has a special need to keep the object around. In addition to unnecessary resources (such as memory and instances of codecs) being held, failure to call this method immediately if a MediaPlayer object is no longer needed may also lead to continuous battery consumption for mobile devices, and playback failure for other applications if no multiple instances of the same codec are supported on a device. Even if multiple instances of the same codec are supported, some performance degradation may be expected when unnecessary multiple instances are used at the same time.
reset():
Resets the MediaPlayer to its uninitialized state. After calling this method, you will have to initialize it again by setting the data source and calling prepare().
So based on that you should be called reset()
rather than release()
as you still require the object after a song has played.