h6ah4i / android-openslmediaplayer

Re-implementation of Android's MediaPlayer and audio effect classes based on OpenSL ES APIs.
https://openslmediaplayer.h6ah4i.com
Apache License 2.0
417 stars 97 forks source link

Playback stops after changing several tracks (data sources) in HybridMediaPlayerFactory only.. #26

Closed hunnydarapstar closed 7 years ago

hunnydarapstar commented 7 years ago

Hello h6ah4i first of all amazing mediaplayer library, I just found one glitch while using HybridMediaPlayerFactory when my app changes tracks, after 10-15 changes it suddenly stops playback with no error or warning in logcat too :( This is my code for changing tracks:

GlobalApp.mediaPlayer.reset();
GlobalApp.mediaPlayer.setDataSource(context, Uri.parse("file://mysong"));
 GlobalApp.mediaPlayer.setOnPreparedListener(new IBasicMediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(IBasicMediaPlayer mp) {
GlobalApp.mediaPlayer.start();
}});
GlobalApp.mediaPlayer.prepareAsync();

Above code working fine in case of OpenSLMediaPlayerFactory.. Please Suggest if I am doing something wrong...!!

hunnydarapstar commented 7 years ago

also receiving this error in logcat while using hybridmediaplayerfactory

E/android.media.AudioTrack: AudioTrack.write() called with invalid size (38400) value

h6ah4i commented 7 years ago

@hunnydarapstar Hi. Thank you for the issue report.

I am checking the implementation around using the AudioTrack class in native layer, but I do not see any implementation bugs there. Could you give me more info to investigate it?

Thanks.

hunnydarapstar commented 7 years ago

Hello @h6ah4i

Output thread 0xb5a90a40 type 0 (MIXER): Thread name: AudioOut_D I/O handle: 13 TID: 467 Standby: no Sample rate: 48000 Hz HAL frame count: 1920 HAL format: 0x1 (pcm16) HAL buffer size: 7680 bytes Channel count: 2 Channel mask: 0x00000003 (front-left, front-right) Processing format: 0x1 (pcm16) Processing frame size: 4 bytes Pending config events: none Output device: 0x2 (SPEAKER) Input device: 0 (NONE) Audio source: 0 (default) Normal frame count: 1920 Last write occurred (msecs): 31 Total writes: 21149 Delayed writes: 0 Blocked in write: yes Suspend count: 0 Sink buffer : 0xb5cfb000 Mixer buffer: 0xb5af1000 Effect buffer: 0xb5cfd000 Fast track availMask=0xfe Standby delay ns=3000000000 AudioStreamOut: 0xb61c8230 flags 0x2 (PRIMARY) Thread throttle time (msecs): 4650 AudioMixer tracks: 0x00000001 Master mono: off FastMixer not initialized Stream volumes in dB: 0:0, 1:-6, 2:0, 3:-7.4, 4:-4.5, 5:0, 6:0, 7:-6, 8:-6, 9:0, 10:0, 11:0, 12:0 Normal mixer raw underrun counters: partial=0 empty=0 1 Tracks of which 1 are active Name Active Client Type Fmt Chn mask Session fCount S F SRate L dB R dB Server Main buf Aux Buf Flags UndFrmCnt 0 yes 13358 3 00000005 00000003 2209 4800 A 3 48000 0 0 000AB180 0xb587e000 0x0 0x400 1920 1 Effect Chains 3 effects for session 2209 In buffer Out buffer Active tracks: 0xb587e000 0xb5cfd000 1 Effect ID 27: Session Status State Engine: 02209 000 003 0xb5ca38b0 Descriptor:

Output thread 0xb5a1d700 type 0 (MIXER): Thread name: AudioOut_15 I/O handle: 21 TID: 469 Standby: yes Sample rate: 48000 Hz HAL frame count: 240 HAL format: 0x1 (pcm16) HAL buffer size: 960 bytes Channel count: 2 Channel mask: 0x00000003 (front-left, front-right) Processing format: 0x5 (pcmfloat) Processing frame size: 8 bytes Pending config events: none Output device: 0x2 (SPEAKER) Input device: 0 (NONE) Audio source: 0 (default) Normal frame count: 960 Last write occurred (msecs): 30038 Total writes: 21987 Delayed writes: 0 Blocked in write: no Suspend count: 0 Sink buffer : 0xb5ae3000 Mixer buffer: 0xb5ae1000 Effect buffer: 0xb618c000 Fast track availMask=0xfc Standby delay ns=3000000000 AudioStreamOut: 0xb61c8268 flags 0x4 (FAST) Thread throttle time (msecs): 0 AudioMixer tracks: 0x00000006 Master mono: off FastMixer command=COLD_IDLE writeSequence=177168 framesWritten=21260160 numTracks=1 writeErrors=0 underruns=16 overruns=47 sampleRate=48000 frameCount=240 measuredWarmup=15.9 ms, warmupCycles=6 mixPeriod=5.00 ms Simple moving statistics over last 3.2 seconds: wall clock time in ms per mix cycle: mean=5.00 min=4.10 max=5.90 stddev=0.10 raw CPU load in us per mix cycle: mean=130 min=0 max=951 stddev=65 Fast tracks: sMaxFastTracks=8 activeMask=0x1 Index Active Full Partial Empty Recent Ready 0 yes 904 0 0 full 1200 1 no 0 0 0 full 0 2 no 546 0 100 empty 0 3 no 0 0 0 full 0 4 no 0 0 0 full 0 5 no 0 0 0 full 0 6 no 0 0 0 full 0 7 no 0 0 0 full 0 Stream volumes in dB: 0:0, 1:-6, 2:0, 3:0, 4:-4.5, 5:0, 6:0, 7:-6, 8:-6, 9:0, 10:0, 11:0, 12:0 Normal mixer raw underrun counters: partial=0 empty=0 2 Tracks of which 0 are active Name Active Client Type Fmt Chn mask Session fCount S F SRate L dB R dB Server Main buf Aux Buf Flags UndFrmCnt 2 no 1084 1 00000001 00000003 2169 8329 S 1 44100 -inf -inf 00004112 0xb5ae3000 0x0 0x600 0 F 1 no 1262 0 00000001 00000001 361 960 I 0 48000 -10 -10 00000000 0xb5ae3000 0x0 0x000 0 0 Effect Chains

USB audio module: No output streams.

No input streams.

Reroute submix audio module: route[0] rate in=0 out=0, addr=[] route[1] rate in=0 out=0, addr=[] route[2] rate in=0 out=0, addr=[] route[3] rate in=0 out=0, addr=[] route[4] rate in=0 out=0, addr=[] route[5] rate in=0 out=0, addr=[] route[6] rate in=0 out=0, addr=[] route[7] rate in=0 out=0, addr=[] route[8] rate in=0 out=0, addr=[] route[9] rate in=48000 out=48000, addr=[]

hunnydarapstar commented 7 years ago

I will give the sample project soon... till then you can have a look at this. Thanks :)

h6ah4i commented 7 years ago

@hunnydarapstar Hi. I have just fixed the AudioTrack warning message bug 🎉 However it does not affect to the playback stopping issue though, so I'll continue trying to fix it on this weekend.

hunnydarapstar commented 7 years ago

@h6ah4i Thanks for putting in the brilliant effort, you have already done marvelous job by creating this library. kudos. I know you 'll fix this soon.

h6ah4i commented 7 years ago

@hunnydarapstar Still I cannot get reproduced the playback stopping issue on my setup. I hope your sample project will break through the current situation.

hunnydarapstar commented 7 years ago

@h6ah4i Hiii I have created sample project for you on github. Take a look here https://github.com/hunnydarapstar/sample-openslmediaplayer-buggy To reproduce the bug, you have to carefully change 20-25 tracks (make sure you are testing on device having more than 30 tracks), after sometime while you forward a track, playback will stop and you can start your investigation. If you need any help regarding reproducing the bug, Feel free to ask. Thanks :)

hunnydarapstar commented 7 years ago

P.S I use openslmediaplayer library in build.gradle via compile 'com.h6ah4i.android:openslmediaplayer:0.7.2' and do not have NDK installed in Android Studio.

h6ah4i commented 7 years ago

@hunnydarapstar Thanks for the sample app! I've been trying to reproduce the bug using the app, but still it does not occur on my setups;

[Devices]

[Media files]

Is this issue can easily be reproduced on both of your devices? Also, I want to know that this issue can be reproduced when using OpenSLMediaPlayerFactory instead of HybridMediaPlayerFactory.


BTW, I found an another issue related to Android 7.0+. I am going to dig into this and possibly I will report it to Google.

https://github.com/h6ah4i/android-openslmediaplayer/issues/28

h6ah4i commented 7 years ago

UPDATE I've just reproduced the bug on my Nexus 5X!

Also, I tweaked the sample app to automate the testing

hunnydarapstar commented 7 years ago

@h6ah4i info : this bug is only present while we use HybridMediaPlayerFactory. You reproduced the bug, now thats called progress :) and one more thing when playback stops you just toggle play/pause 4-5 times and again change 2-3 tracks, the playback will start again. I probably suspect when the bug is encountered, mediaplayer is hanged in some state, which it revives after again changing tracks.

hunnydarapstar commented 7 years ago

Hii @h6ah4i
Any updates on this issue ?

h6ah4i commented 7 years ago

@hunnydarapstar Have you tested the latest code on the develop branch? I think this issue has been resolved by the commit ea3c0f0. (I thought you have already successful to build the library because your question post on issue #22 has been removed.)

hunnydarapstar commented 7 years ago

@h6ah4i On issue #22 my question was resolved but I again encountered another error while building the project

Android NDK: WARNING: Ignoring unknown import directory:  F:/AndroidExamples/android-openslmediaplayer/library/src/main/jni/../dep_libs/cxxdasp/android/dep_libs/cxxporthelper/android/module    
Android NDK: F:/AndroidExamples/android-openslmediaplayer/library/src/main/jni/cxxporthelper/Android.mk: Cannot find module with tag 'cxxporthelper/cxxporthelper' in import path    

F:/AndroidExamples/android-openslmediaplayer/library/src/main/jni/cxxporthelper/Android.mk:21: *** Android NDK: Aborting.    .  Stop.

Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?    
Android NDK: The following directories were searched:    
Android NDK:         
make: Entering directory `F:/AndroidExamples/android-openslmediaplayer/library/src/main/jni'
make: Leaving directory `F:/AndroidExamples/android-openslmediaplayer/library/src/main/jni'
:library:ndkBuildReleaseNonJniDebuggable FAILED

Can you fix this ?

h6ah4i commented 7 years ago

@hunnydarapstar I am not sure what is happening, but at least it seems that you have not used SUBST command yet. Gnu tools cannot handle the path name longer than MAX_PATH (=260 chars), so you have to take care about that.

SUBST X: F:/AndroidExamples/android-openslmediaplayer
hunnydarapstar commented 7 years ago

Finally, I managed to build the library, and tons of thanks the issue has been resolved. Thank you for doing a brilliant job in maintaining the library, best of luck for future :1st_place_medal: