ExoPlayer - how to play local mp3 file

前端 未结 4 585
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 13:37

I\'m trying to use ExoPlayer instead of MediaPlayer because it\'s a common bug that MediaPlayer returns wrong getCurrentPosition() and I need a substitute.

But I can\'t

4条回答
  •  我在风中等你
    2021-02-07 13:52

    Using ExoPlayer 2.1, and starting with the demo project, you can play mp3 files from the assets folder without modifying any Java code, just by adding the mp3 files in the assets folder and creating or modifying a json file. Starting with the ExoPlayer demo project:

    1. Put the mp3 files in the demo/assets folder (with media.exolist.json).

    2. Either modify media.exolist.json or create a new file such as my.exolist.json containing one or more entries formatted like this:

    { "name": "Children's Songs", "samples": [ { "name": "Mary Had a Little Lamb", "uri": "asset:///mary1.mp3" }, { "name": "Itsy Bitsy Spider", "uri": "asset:///spider1.mp3" } ] },

    (The final comma assumes there will be another category following, such as Blues Songs, Jazz Songs etc. with more mp3 entries. The final category has no comma after it.)

    The figure below shows the chooser activity screen after you click on Children's Songs:

    Click Mary Had a Little Lamb or Itsy Bitsy Spider and that mp3 plays.

提交回复
热议问题