How to avoid 15 second delay/caching in Android Media Player when playing stream

后端 未结 4 2233
迷失自我
迷失自我 2021-02-15 17:57

I am implementing a media player that plays a stream from a remote machine. Via my app I can control the remote machine (e.g. seek to second). Works like charm, but: The Android

相关标签:
4条回答
  • 2021-02-15 18:30

    One thing I realized in the newer Android versions is that it seems to have issues with VBR MP3 files. It plays them, but buffers way too much data before it starts. (3+ MB, the majority of my test files).

    A (bad hack) workaround is to remove the XING header from the MP3 files (this is where the VBR information is stored). This seems to make the player fall back to a simpler algorithm and start playback successfully for all my files after buffering only 100kb...

    0 讨论(0)
  • 2021-02-15 18:35

    Try this. this will definatly help to you ::

     private class TouchandshowTask extends AsyncTask<Void, Void, Void> {
    
        @Override
        protected Void doInBackground(Void... arg0) {
            try {
            player.setAudioStreamType(AudioManager.STREAM_MUSIC);
            player.setDataSource("URL");
            player.prepare();
        } catch (Exception e) {
            // TODO: handle exception
        }
    
            return null;
        }
        protected void onPostExecute(final Void unused) {
    
        }
    }
    

    OnCreate()

    new TouchandshowTask().execute();
    
    0 讨论(0)
  • 2021-02-15 18:36

    The problem might be not only at Android Media Player. Server that is streaming video should support need format.

    If it's mp4's you need to install h264-pseudo-streaming module (same for HLS) If it's MSS (microsoft smooth streaming) - there are special modules for IIS.

    Also, after user 'makes seek' that means Native Player will send range request, that should be supported by server. Nginx supports them by default, ISS & Apache have some issues with this. Though easy configurable.

    0 讨论(0)
  • 2021-02-15 18:47

    Ok, meanwhile I got closer to the solution. Turned out the source of my problem is Android DRM! (No, I am not playing a protected file. Its standard mp3).

    DRM seems to have been introduced in Android 3.1 (I was testing on a Galaxy Tab 10.1). It works fine on the Emulator (maybe DRM is not implemented there?)

    Any idea how I can disable or accelerate this? There seems to be a 10 seconds timer somewhere deep in the Android DRM impl that waits for - whatever, no idea. My error log:

    10-06 17:38:19.020: ERROR/MediaExtractor(226): **********MediaExtractor::Create
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(226): add uniqueid
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(225): Entering BnDrmManagerService::onTransact with code 1
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(225): BnDrmManagerService::onTransact :ADD_UNIQUEID
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(225): Entering BnDrmManagerService::onTransact with code 3
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(225): BnDrmManagerService::onTransact :ADD_CLIENT
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(226): Entering BpDrmManagerService::openDecryptSession
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(225): Entering BnDrmManagerService::onTransact with code 27
    10-06 17:38:19.020: ERROR/IDrmManagerService(Native)(225): BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI
    10-06 17:38:19.020: ERROR/DrmManagerService(Native)(225): Entering DrmManagerService::openDecryptSession with uri
    
    10 seconds wait
    
    10-06 17:38:29.040: ERROR/DrmManager(Native)(225): DrmManager::openDecryptSession: no capable plug-in found
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): NULL decryptHandle is returned
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(226): no decryptHandle is generated in service side
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(226): remove uniqueid
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): Entering BnDrmManagerService::onTransact with code 2
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): BnDrmManagerService::onTransact :REMOVE_UNIQUEID
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): Entering BnDrmManagerService::onTransact with code 4
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): BnDrmManagerService::onTransact :REMOVE_CLIENT
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(226): setDrmServiceListener
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): Entering BnDrmManagerService::onTransact with code 5
    10-06 17:38:29.040: ERROR/IDrmManagerService(Native)(225): BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER
    10-06 17:38:29.040: ERROR/DrmManagerService(Native)(225): Entering setDrmServiceListener
    
    0 讨论(0)
提交回复
热议问题