MediaPlayer setDataSource need best practice advice

后端 未结 1 961
感动是毒
感动是毒 2021-01-12 10:15

After reading \"Media Playback\" and \"MediaPlayer\" android documentations I\'m still confused and need experienced advice about setDataSource overloaded method.

I

相关标签:
1条回答
  • 2021-01-12 11:06

    There aren't any real benefits to the various ways of calling create or setDataSource. The static create methods don't do much more than call setDataSource and prepare. The various setDataSource methods call each other internally. Eventually they boil down to two possible native calls, one with a string describing a remote URI and another with a local file descriptor. There may be a very slight performance advantage to creating the file descriptor yourself, but it will not be appreciable in context.

    For local file playback, as you are demonstrating in your code, simply calling prepare (or the static create methods) isn't a bad practice at all. The underlying player should have no problem determining the relevant metadata and returning quickly no matter the size of the file. The prepareAsync method is more useful for network streams, where any number of situations might cause some unexpected delay. If you are designing a general purpose player, then using the prepareAsync method would be the way to go, but if you are simply playing raw assets it shouldn't make any difference. The variety of methods provided is simply a matter of convenience (take note of the javadoc for create).

    0 讨论(0)
提交回复
热议问题