Android Media Player无法通过PVMFErrNotSupported支持MP3?

我有一个下载的MP3,可以通过adb将其验证为MP3,然后将其拖到我的Mac或PC上并在其各自的媒体播放器中播放.但是,来自Android的错误表明它不支持该格式.我认为这可能与我存储文件的目录位置有关,但这没有任何意义(/data/data/com.myapp/files/file_audio.mp3).这是AsyncTask中的代码:

    protected String doInBackground(String... params) {

        String filename = params[0];

        try {
            StringBuilder filenameMp3 = new StringBuilder().append(context.getFilesDir());
            filenameMp3.append("/").append(filename);

            Uri uriMp3 = Uri.parse(filenameMp3.toString());
            Log.d(TAG, "Listen to this ringtone! [" + uriMp3.toString() + "]");

            MediaPlayer mp = MediaPlayer.create(context, uriMp3);
            mp.prepare();
            mp.start();
        } catch (IllegalStateException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }

        return null;
    }

这是日志:

09-07 23:16:09.617 E/MediaPlayerService( 1128): The Default Player is PV_PLAYER***********************
09-07 23:16:09.617 V/PVPlayer( 1128): PVPlayer constructor
09-07 23:16:09.617 V/PVPlayer( 1128): construct PlayerDriver
09-07 23:16:09.617 V/PlayerDriver( 1128): constructor
09-07 23:16:09.627 V/PlayerDriver( 1128): OpenCore hardware module loaded
09-07 23:16:09.627 V/PlayerDriver( 1128): start player thread
09-07 23:16:09.627 V/PlayerDriver( 1128): startPlayerThread
09-07 23:16:09.627 V/PlayerDriver( 1128): InitializeForThread
09-07 23:16:09.627 V/PlayerDriver( 1128): OMX_MasterInit
09-07 23:16:09.647 V/PlayerDriver( 1128): OsclScheduler::Init
09-07 23:16:09.647 V/PlayerDriver( 1128): CreatePlayer
09-07 23:16:09.657 V/PlayerDriver( 1128): AddToScheduler
09-07 23:16:09.657 V/PlayerDriver( 1128): PendForExec
09-07 23:16:09.657 V/PlayerDriver( 1128): OsclActiveScheduler::Current
09-07 23:16:09.657 V/PlayerDriver( 1128): StartScheduler
09-07 23:16:09.657 V/PVPlayer( 1128): send PLAYER_SETUP
09-07 23:16:09.667 V/PlayerDriver( 1128): Send player code: 2
09-07 23:16:09.667 V/PlayerDriver( 1128): CommandCompleted
09-07 23:16:09.667 V/PlayerDriver( 1128): Completed command PLAYER_SETUP status=PVMFSuccess
09-07 23:16:09.667 V/PVPlayer( 1128): setDataSource(/data/data/com.myapp/files/audio.mp3)
09-07 23:16:09.667 V/PVPlayer( 1128): prepareAsync
09-07 23:16:09.667 V/PVPlayer( 1128):   data source = /data/data/com.myapp/files/audio.mp3
09-07 23:16:09.667 V/PlayerDriver( 1128): Send player code: 3
09-07 23:16:09.667 V/PlayerDriver( 1128): handleSetDataSource
09-07 23:16:09.667 V/PlayerDriver( 1128): handleSetDataSource- scanning for extension
09-07 23:16:09.667 V/PlayerDriver( 1128): HandleInformationalEvent: PVMFInfoErrorHandlingStart
09-07 23:16:09.667 V/PlayerDriver( 1128): HandleInformationalEvent: type=26 UNHANDLED
09-07 23:16:09.667 W/MediaPlayer(14630): info/warning (1, 26)
09-07 23:16:09.667 I/MediaPlayer(14630): Info (1,26)
09-07 23:16:09.667 V/PlayerDriver( 1128): CommandCompleted
09-07 23:16:09.667 V/PlayerDriver( 1128): Completed command PLAYER_SET_DATA_SOURCE status=PVMFErrNotSupported
09-07 23:16:09.667 E/PlayerDriver( 1128): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
09-07 23:16:09.667 E/MediaPlayer(14630): error (1, -4)
09-07 23:16:09.677 V/PVPlayer( 1128): run_init s=-2147483648, cancelled=0
09-07 23:16:09.677 V/PlayerDriver( 1128): HandleInformationalEvent: PVMFInfoErrorHandlingComplete
09-07 23:16:09.677 W/PlayerDriver( 1128): PVMFInfoErrorHandlingComplete

有什么线索吗?

解决方法:

FileInputStream fis = getBaseContext().openFileInput(filename.toString());
mp = new MediaPlayer();
mp.setOnCompletionListener(onCompleteAudioListener);
mp.setDataSource(fis.getFD());
mp.prepare();
mp.start();

加上正常的检查和错误处理.

上一篇:CodeGo.net>获取MP3文件的长度


下一篇:关于采样率&位深&码率&无损的一些心得