Просмотр исходного кода

替换华为提供的预编译库,可以拖动wma,但是暂时禁用均衡器功能

chendeben 6 месяцев назад
Родитель
Сommit
c59962130b

+ 4 - 2
ijkplayer/oh_modules/@types/libijkplayer_audio_napi.so/index.d.ts

@@ -45,6 +45,8 @@ export declare class newIjkPlayerAudio {
   _getAudioCodecInfo(xcomponentId: string): string;
   _getAudioCodecInfo(xcomponentId: string): string;
   _getMediaMeta(xcomponentId: string): string;
   _getMediaMeta(xcomponentId: string): string;
   _native_setup(xcomponentId: string): void;
   _native_setup(xcomponentId: string): void;
-  _setEqualizerEnabled(xcomponentId: string, enabled: boolean): void;
-  _setEqualizerGains(xcomponentId: string, gains: number[]): void;
+  // 均衡器功能暂时禁用 - 华为官方库不支持
+  // 后续通过源码编译方式重新添加
+  // _setEqualizerEnabled(xcomponentId: string, enabled: boolean): void;
+  // _setEqualizerGains(xcomponentId: string, gains: number[]): void;
 }
 }

+ 21 - 1
ijkplayer/src/main/cpp/ijkplayer/ff_ffplay.c

@@ -3411,7 +3411,27 @@ static int read_thread(void *arg)
 
 
             ffp_toggle_buffering(ffp, 1);
             ffp_toggle_buffering(ffp, 1);
             ffp_notify_msg3(ffp, FFP_MSG_BUFFERING_UPDATE, 0, 0);
             ffp_notify_msg3(ffp, FFP_MSG_BUFFERING_UPDATE, 0, 0);
-            ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, is->seek_flags);
+
+            // Workaround for ASF/WMA seek crash (FFmpeg ff_seek_frame_binary uninitialized variable issue)
+            // See: https://ffmpeg.org/pipermail/ffmpeg-cvslog/2024-April/142447.html
+            // For ASF format, use AVSEEK_FLAG_BACKWARD to avoid triggering binary seek with uninitialized pos_min/pos_max
+            int seek_flags = is->seek_flags;
+            int is_asf_format = (ic->iformat && ic->iformat->name && !strcmp(ic->iformat->name, "asf"));
+            if (is_asf_format) {
+                seek_flags |= AVSEEK_FLAG_BACKWARD;
+                av_log(ffp, AV_LOG_DEBUG, "ASF format detected, using AVSEEK_FLAG_BACKWARD for seek\n");
+            }
+
+            ret = avformat_seek_file(is->ic, -1, seek_min, seek_target, seek_max, seek_flags);
+
+            // Fallback for ASF format: if seek failed, try with audio stream index
+            if (ret < 0 && is_asf_format && is->audio_stream >= 0) {
+                av_log(ffp, AV_LOG_WARNING, "ASF seek failed, trying fallback with audio stream index\n");
+                // Convert seek_target from AV_TIME_BASE to audio stream time_base
+                int64_t seek_ts = av_rescale_q(seek_target, AV_TIME_BASE_Q, is->audio_st->time_base);
+                ret = av_seek_frame(is->ic, is->audio_stream, seek_ts, seek_flags | AVSEEK_FLAG_ANY);
+            }
+
             if (ret < 0) {
             if (ret < 0) {
                 av_log(NULL, AV_LOG_ERROR,
                 av_log(NULL, AV_LOG_ERROR,
                        "%s: error while seeking\n", is->ic->filename);
                        "%s: error while seeking\n", is->ic->filename);

+ 8 - 16
ijkplayer/src/main/cpp/proxy/ijkplayer_napi_proxy.cpp

@@ -593,23 +593,15 @@ void IJKPlayerNapiProxy::IjkMediaPlayer_native_openlog() {
 }
 }
 
 
 void IJKPlayerNapiProxy::IjkMediaPlayer_setEqualizerEnabled(bool enabled) {
 void IJKPlayerNapiProxy::IjkMediaPlayer_setEqualizerEnabled(bool enabled) {
-    OH_LOG_Print(LOG_APP, LOG_INFO, 0xB000, "IjkAudioEq", "Proxy setEqualizerEnabled: %{public}d", enabled);
-    IjkMediaPlayer *mp = IJKPlayerNapiProxy::get_media_player(id_);
-    if (!mp) {
-        LOGE("napi_proxy->IjkMediaPlayer_setEqualizerEnabled mp NULL");
-        return;
-    }
-    ijkmp_android_set_equalizer_enabled(mp, enabled);
-    ijkmp_dec_ref_p(&mp);
+    // 均衡器功能暂时禁用 - 华为官方库不支持
+    // 后续通过源码编译方式重新添加
+    OH_LOG_Print(LOG_APP, LOG_WARN, 0xB000, "IjkAudioEq", "Equalizer disabled - using official library without EQ support");
+    (void)enabled; // 避免未使用参数警告
 }
 }
 
 
 void IJKPlayerNapiProxy::IjkMediaPlayer_setEqualizerGains(const float *gains) {
 void IJKPlayerNapiProxy::IjkMediaPlayer_setEqualizerGains(const float *gains) {
-    OH_LOG_Print(LOG_APP, LOG_INFO, 0xB000, "IjkAudioEq", "Proxy setEqualizerGains band0: %{public}f", gains[0]);
-    IjkMediaPlayer *mp = IJKPlayerNapiProxy::get_media_player(id_);
-    if (!mp) {
-        LOGE("napi_proxy->IjkMediaPlayer_setEqualizerGains mp NULL");
-        return;
-    }
-    ijkmp_android_set_equalizer_gains(mp, gains);
-    ijkmp_dec_ref_p(&mp);
+    // 均衡器功能暂时禁用 - 华为官方库不支持
+    // 后续通过源码编译方式重新添加
+    OH_LOG_Print(LOG_APP, LOG_WARN, 0xB000, "IjkAudioEq", "Equalizer disabled - using official library without EQ support");
+    (void)gains; // 避免未使用参数警告
 }
 }

+ 4 - 2
ijkplayer/src/main/cpp/types/ijkplayer_audio_napi/index.d.ts

@@ -45,6 +45,8 @@ export declare class newIjkPlayerAudio {
   _getAudioCodecInfo(xcomponentId: string): string;
   _getAudioCodecInfo(xcomponentId: string): string;
   _getMediaMeta(xcomponentId: string): string;
   _getMediaMeta(xcomponentId: string): string;
   _native_setup(xcomponentId: string): void;
   _native_setup(xcomponentId: string): void;
-  _setEqualizerEnabled(xcomponentId: string, enabled: boolean): void;
-  _setEqualizerGains(xcomponentId: string, gains: number[]): void;
+  // 均衡器功能暂时禁用 - 华为官方库不支持
+  // 后续通过源码编译方式重新添加
+  // _setEqualizerEnabled(xcomponentId: string, enabled: boolean): void;
+  // _setEqualizerGains(xcomponentId: string, gains: number[]): void;
 }
 }

+ 14 - 12
ijkplayer/src/main/ets/ijkplayer/IjkMediaPlayer.ets

@@ -252,21 +252,23 @@ export class IjkMediaPlayer {
   }
   }
 
 
   setEqualizerEnabled(enabled: boolean): void {
   setEqualizerEnabled(enabled: boolean): void {
-    if (this.ijkplayer_audio_napi) {
-      this.ijkplayer_audio_napi._setEqualizerEnabled(this.id, enabled);
-    } else if (!!this.ijkplayer_napi) {
-      // Video player also has equalizer support
-      this.ijkplayer_napi._setEqualizerEnabled?.(this.id, enabled);
-    }
+    // 均衡器功能暂时禁用 - 使用华为官方库后不支持
+    // 后续通过源码编译方式重新添加
+    // if (this.ijkplayer_audio_napi) {
+    //   this.ijkplayer_audio_napi._setEqualizerEnabled(this.id, enabled);
+    // } else if (!!this.ijkplayer_napi) {
+    //   this.ijkplayer_napi._setEqualizerEnabled?.(this.id, enabled);
+    // }
   }
   }
 
 
   setEqualizerGains(gains: number[]): void {
   setEqualizerGains(gains: number[]): void {
-    if (this.ijkplayer_audio_napi) {
-      this.ijkplayer_audio_napi._setEqualizerGains(this.id, gains);
-    } else if (!!this.ijkplayer_napi) {
-      // Video player also has equalizer support
-      this.ijkplayer_napi._setEqualizerGains?.(this.id, gains);
-    }
+    // 均衡器功能暂时禁用 - 使用华为官方库后不支持
+    // 后续通过源码编译方式重新添加
+    // if (this.ijkplayer_audio_napi) {
+    //   this.ijkplayer_audio_napi._setEqualizerGains(this.id, gains);
+    // } else if (!!this.ijkplayer_napi) {
+    //   this.ijkplayer_napi._setEqualizerGains?.(this.id, gains);
+    // }
   }
   }