CarGuo / GSYVideoPlayer

视频播放器(IJKplayer、ExoPlayer、MediaPlayer),HTTPS,16k page size,支持弹幕,外挂字幕,支持滤镜、水印、gif截图,片头广告、中间广告,多个同时播放,支持基本的拖动,声音、亮度调节,支持边播边缓存,支持视频自带rotation的旋转(90,270之类),重力旋转与手动旋转的同步支持,支持列表播放 ,列表全屏动画,视频加载速度,列表小窗口支持拖动,动画效果,调整比例,多分辨率切换,支持切换播放器,进度条小窗口预览,列表切换详情页面无缝播放,rtsp、concat、mpeg。
https://juejin.cn/user/817692379985752/posts
Apache License 2.0
20.24k stars 4.2k forks source link

播放rtsp流和开始播放时 失去音频焦点无法播放 #3671

Closed 2799448671 closed 2 years ago

2799448671 commented 2 years ago

问题描述:

场景描述: 使用一台猫精定制的设备 在开始播放和播放过程中 喊天猫精灵唤出猫精语音 类似于小米或苹果的语音助手 此时视频会暂停且不在播放 监听onAudioFocusChange也只会在开始播放时运行一次 如何能够不被语音助手影响播放

GSY依赖版本

//基础包 api 'com.shuyu:gsyVideoPlayer-java:7.1.4' //是否需要ExoPlayer模式 api 'com.shuyu:GSYVideoPlayer-exo2:7.1.4' //更多ijk的编码支持 api 'com.shuyu:gsyVideoPlayer-ex_so:7.1.4'

问题log(如果有)

2022-08-17 15:01:34.035 18352-20253/com.alibaba.doorbell V/IJKMEDIA: id=0 len=671
2022-08-17 15:01:34.035 18352-20253/com.alibaba.doorbell V/IJKMEDIA: tcp_read_packet:
2022-08-17 15:01:34.042 18352-20262/com.alibaba.doorbell D/IJKMEDIA: nal_unit_type: 1, nal_ref_idc: 2
2022-08-17 15:01:34.070 18352-20253/com.alibaba.doorbell V/IJKMEDIA: ret=1 c=24 [$]
2022-08-17 15:01:34.070 18352-20253/com.alibaba.doorbell V/IJKMEDIA: id=0 len=1456
2022-08-17 15:01:34.074 18352-18352/com.alibaba.doorbell D/AudioManager: dispatching onAudioFocusChange(-2) to android.media.AudioManager@4fb46facom.shuyu.gsyvideoplayer.video.base.GSYVideoView$1@99f0c84
2022-08-17 15:01:34.075 18352-18352/com.alibaba.doorbell D/IJKMEDIA: ijkmp_pause()
2022-08-17 15:01:34.075 18352-18352/com.alibaba.doorbell D/IJKMEDIA: ijkmp_pause()=0
2022-08-17 15:01:34.075 18352-20251/com.alibaba.doorbell D/IJKMEDIA: ijkmp_get_msg: FFP_REQ_PAUSE
2799448671 commented 2 years ago

image 我在GSYVideoView中找到了实现的onAudioFocusChange方法但要如何修改

CarGuo commented 2 years ago

参考demo里的 https://github.com/CarGuo/GSYVideoPlayer/blob/master/app/src/main/java/com/example/gsyvideoplayer/video/MultiSampleVideo.java#L56

2799448671 commented 2 years ago

解决了 自定义了一个View集成StandardGSYVideoPlayer 重写了onLossTransientAudio()方法

vickyleu commented 1 month ago

解决了 自定义了一个View集成StandardGSYVideoPlayer 重写了onLossTransientAudio()方法

终于找到了, 目前我使用compose multiplatform 写了个app, 只要一跳转页面, 播放器就会卡死无法再播放,找了各种办法都不奏效,最终发现就是这个导致的

@CarGuo 因为有一个onAudioFocusChange 状态等于-2,所以视频再重复播放都被这个-2 给pause了

OpenGLRenderer           D  gpu complete is not signaled
rg.uooc.compos           I  NativeAlloc concurrent copying GC freed 447390(20MB) AllocSpace objects, 29(736KB) LOS objects, 34% free, 45MB/69MB, paused 911us,536us total 120.961ms cpu time 94.878ms DisableRefAccess:2.778ms(2.236ms), OnTop
HwViewRootImpl           I  removeInvalidNode jank list is null
OpenGLRenderer           D  gpu complete is not signaled
AudioManager             I  requestAudioFocus streamType: 3 durationHint: 2
AudioManager             W  Use of stream types is deprecated for operations other than volume control
AudioManager             W  See the documentation for what to use instead with android.media.AudioAttributes to qualify your playback use case
AudioManager             D  dispatching onAudioFocusChange(-2) to android.media.AudioManager@cafafb0com.shuyu.gsyvideoplayer.video.base.GSYVideoView$1@759e29
IJKMEDIA                 D  IjkMediaPlayer_release
IJKMEDIA                 D  ijkmp_set_android_surface(surface=0x0)
IJKMEDIA                 D  ffpipeline_set_surface()
IJKMEDIA                 D  ijkmp_set_android_surface(surface=0x0)=void
IJKMEDIA                 D  ijkmp_shutdown_l()
IJKMEDIA                 D  message_loop exit
IJKMEDIA                 I  SDL_JNI_DetachThreadEnv: [26896]
IJKMEDIA                 I  SDL_JNI_DetachThreadEnv: [26897]
IJKMEDIA                 I  SDL_JNI_DetachThreadEnv: [26898]
IJKMEDIA                 I  SDL_JNI_DetachThreadEnv: [26902]
AudioTrack               I  stop(128): prior state:STATE_PAUSED
AudioTrack               D  stop(128): called with 291968 frames delivered
PlayerBase               V  baseStop() piid=959
PlayerBase               D  [HSM] PlayerBase stop() uid: 10293, pid: 26396
PlayerBase               V  baseRelease() piid=959 state=4
PlayerBase               D  [HSM] PlayerBase stop() uid: 10293, pid: 26396
AudioTrack               I  stop(128): prior state:STATE_STOPPED
AudioSystem              I  setErrorCallback:android.media.AudioTrack$1@abcef0c type:-1
IJKMEDIA                 I  SDL_JNI_DetachThreadEnv: [26901]
IJKMEDIA                 I  SDL_JNI_DetachThreadEnv: [26912]
IJKMEDIA                 E  SDL_Overlay(ffmpeg): overlay_free_l(0xb40000762af97e00)
IJKMEDIA                 E  SDL_Overlay(ffmpeg): overlay_free_l(0xb40000762af97e70)
IJKMEDIA                 E  SDL_Overlay(ffmpeg): overlay_free_l(0xb4000075cdc7a7f0)
IJKMEDIA                 D  ijkmp_shutdown_l()=void
IJKMEDIA                 D  ijkmp_dec_ref(): ref=0
IJKMEDIA                 D  ijkmp_shutdown_l()
IJKMEDIA                 D  ijkmp_shutdown_l()=void
IJKMEDIA                 D  IjkMediaPlayer_native_setup
IJKMEDIA                 D  ffpipeline_create_from_android()
IJKMEDIA                 D  ijkmp_set_inject_opaque(0x24fa)
IJKMEDIA                 D  ijkmp_set_inject_opaque()=void
IJKMEDIA                 D  ijkmp_set_ijkio_inject_opaque(0x24fa)
IJKMEDIA                 D  ijkmp_set_ijkio_inject_opaque()=void
IJKMEDIA                 D  ijkmp_android_set_mediacodec_select_callback()
IJKMEDIA                 D  ffpipeline_set_mediacodec_select_callback
IJKMEDIA                 D  ijkmp_android_set_mediacodec_select_callback()=void
IJKMEDIA                 D  IjkMediaPlayer_setDataSourceAndHeaders
IJKMEDIA                 V  setDataSource: path /data/user/0/org.uooc.compose/cache/video-cache/4b693a54dd5c1d38ad24bdc81dae0a80.mp4
IJKMEDIA                 D  ijkmp_set_data_source(url="/data/user/0/org.uooc.compose/cache/video-cache/4b693a54dd5c1d38ad24bdc81dae0a80.mp4")
IJKMEDIA                 D  ijkmp_set_data_source(url="/data/user/0/org.uooc.compose/cache/video-cache/4b693a54dd5c1d38ad24bdc81dae0a80.mp4")=0
IJKMEDIA                 D  IjkMediaPlayer_setOptionLong
IJKMEDIA                 D  IjkMediaPlayer_setLoopCount
IJKMEDIA                 D  IjkMediaPlayer_native_setLogLevel(8)
IJKMEDIA                 D  moncleanup
IJKMEDIA                 D  IjkMediaPlayer_setVolume
IJKMEDIA                 D  ijkmp_android_set_volume(1.000000, 1.000000)
IJKMEDIA                 D  ffpipeline_set_volume
IJKMEDIA                 D  ijkmp_android_set_volume(1.000000, 1.000000)=void
tv.danmaku...ediaPlayer  W  setScreenOnWhilePlaying(true) is ineffective without a SurfaceHolder
IJKMEDIA                 D  IjkMediaPlayer_prepareAsync
IJKMEDIA                 D  ijkmp_prepare_async()
IJKMEDIA                 D  ijkmp_prepare_async()=0
IJKMEDIA                 I  SDL_RunThread: [27002] ff_read
IJKMEDIA                 I  SDL_RunThread: [27000] ff_msg_loop
IJKMEDIA                 D  message_loop
IJKMEDIA                 D  FFP_MSG_FLUSH:
IJKMEDIA                 I  SDL_RunThread: [27001] ff_vout
IJKMEDIA                 D  FFP_MSG_OPEN_INPUT:
IJKMEDIA                 D  IjkMediaPlayer_setVolume
IJKMEDIA                 D  ijkmp_android_set_volume(0.000000, 0.000000)
IJKMEDIA                 D  ffpipeline_set_volume
IJKMEDIA                 D  ijkmp_android_set_volume(0.000000, 0.000000)=void
IJKMEDIA                 D  FFP_MSG_FIND_STREAM_INFO:
IJKMEDIA                 I  SDL_Android_AudioTrack: CHANNEL_OUT_STEREO
IJKMEDIA                 I  SDL_Android_AudioTrack: ENCODING_PCM_16BIT
AudioTrack-JNI           I  AudioTrack_setup for usage=1 content=2 flags=0x0x800 tags=
AudioTrack               D  set(): Building AudioTrack with attributes: usage=1 content=2 flags=0x800 tags=[]
AudioTrack               I  setVolumeLR : 1.000000
AudioSystem              I  setErrorCallback:android.media.AudioTrack$1@4898efe type:1
android.me...AudioTrack  E  unknown AudioTrack_Buffer_Timeout error type
AudioTrack               W  Use of stream types is deprecated for operations other than volume control
AudioTrack               W  See the documentation for what to use instead with android.media.AudioAttributes to qualify your playback use case
IJKMEDIA                 I  SDL_Android_AudioTrack_new_from_spec: init volume as 1.000000/(0.000000,1.000000)
AudioTrack               I  setVolumeLR : 1.000000
IJKMEDIA                 I  audio_session_id = 961
IJKMEDIA                 I  SDL_RunThread: [27004] ff_aout_android
IJKMEDIA                 I  SDL_RunThread: [27005] ff_audio_dec
PlayerBase               D  baseStart() piid=967 deviceId=0
PlayerBase               D  [HSM] PlayerBase play() uid: 10293, pid: 26396
IJKMEDIA                 D  FFP_MSG_COMPONENT_OPEN:
IJKMEDIA                 D  FFP_MSG_VIDEO_SIZE_CHANGED: 1920, 1080
IJKMEDIA                 D  FFP_MSG_SAR_CHANGED: 0, 1
IJKMEDIA                 D  ijkmp_get_msg: FFP_MSG_PREPARED
IJKMEDIA                 D  FFP_MSG_PREPARED:
IJKMEDIA                 D  IjkMediaPlayer_start
IJKMEDIA                 D  ijkmp_start()
IJKMEDIA                 D  ijkmp_start()=0
IJKMEDIA                 D  ijkmp_get_msg: FFP_REQ_START
IJKMEDIA                 I  SDL_RunThread: [27015] ff_video_dec
IJKMEDIA                 D  FFP_MSG_VIDEO_ROTATION_CHANGED: 0
AudioTrack               I  start(129): prior state:STATE_STOPPED
AudioTrack               W  SendPlayerType(129): send caller name to Track failed.
HwMediaVie...ngeHandler  I  attachLayoutChangeListener: attached listener to view=com.shuyu.gsyvideoplayer.render.view.GSYVideoGLView{90888ac V.E...... ......I. 0,0-0,0}
GLThread                 I  noticed surfaceView surface lost tid=2688
IJKMEDIA                 D  ijkmp_pause()
IJKMEDIA                 D  ijkmp_pause()=0
IJKMEDIA                 D  ijkmp_get_msg: FFP_REQ_PAUSE
AudioTrack               I  pause(129): prior state:STATE_ACTIVE
HwMediaVie...ngeHandler  I  handleMediaViewLayoutChanged, listener removed. view=com.shuyu.gsyvideoplayer.render.view.GSYVideoGLView{90888ac V.E...... ........ 0,57-912,570}
PlayerBase               V  basePause() piid=967
PlayerBase               D  [HSM] PlayerBase pause() uid: 10293, pid: 26396
IJKMEDIA                 D  SDL_VoutFFmpeg_CreateOverlay(w=1920, h=1080, fmt=RV32(0x32335652, dp=0xb40000768379f240)
IJKMEDIA                 D  FFP_MSG_VIDEO_SIZE_CHANGED: 1920, 1080
IJKMEDIA                 D  Video: first frame decoded
IJKMEDIA                 D  FFP_MSG_VIDEO_DECODED_START:
IJKMEDIA                 D  SDL_VoutFFmpeg_CreateOverlay(w=1920, h=1080, fmt=RV32(0x32335652, dp=0xb40000768379f240)
IJKMEDIA                 D  FFP_MSG_VIDEO_SIZE_CHANGED: 1920, 1080
IJKMEDIA                 D  SDL_VoutFFmpeg_CreateOverlay(w=1920, h=1080, fmt=RV32(0x32335652, dp=0xb40000768379f240)
IJKMEDIA                 D  FFP_MSG_VIDEO_SIZE_CHANGED: 1920, 1080
BufferQueueCore          D  BufferQueueCore: mDebugHwFlow=0, mIsBufferQueueLogVSupport=0.
SurfaceView              I  ViewUI setLowResolutionInfo compatInfo.supportsScreen() is not satisfied
Main thread              I  surfaceCreated waiting for surface. mWaitingForSurface: true mFinishedCreatingEglSurface: false mExited: false
GLThread                 I  noticed surfaceView surface acquired tid=2688
HwApsImpl                W  not support full screen video recognize feature ## org.uooc.compose
GLThread                 I  noticing that we want render notification tid=2688
GLThread                 I  egl createSurface start.
EglHelper                I  destroySurfaceImp finished in createSurface.
EglHelper                I  create an EGL surface we can render into successfully.
BufferQueueCore          D  BufferQueueCore: mDebugHwFlow=0, mIsBufferQueueLogVSupport=0.
GLThread                 I  sending render notification tid=2688
tv.danmaku...ediaPlayer  W  setScreenOnWhilePlaying(true) is ineffective for Surface
IJKMEDIA                 D  IjkMediaPlayer_setVideoSurface
IJKMEDIA                 D  ijkmp_set_android_surface(surface=0x7fe02603cc)
IJKMEDIA                 D  ffpipeline_set_surface()
IJKMEDIA                 D  ijkmp_set_android_surface(surface=0x7fe02603cc)=void
AudioSystem              I  reportHalLatency latency 0 lightLatency 0 sessionId 961
AudioSystem              E  reportHalLatency fail, no callback found for sessionId 961
AudioSystem              E  onAudioException exceptionId -1003 sessionId 961
AudioSystem              W  onAudioException error:-2103444417 sessionId:961
AudioSystem              I  errorCallbackFromNative error = -2103444417,errorCallback = falseaudioTrackCallback size:1
PlayerBase               V  baseTimeout() piid=967
PlayerBase               D  [HSM] PlayerBase timeout() uid: 10293, pid: 26396
PlayerBase               V  baseStop() piid=967
PlayerBase               D  [HSM] PlayerBase stop() uid: 10293, pid: 26396