Browse Source

优化播放组件

yanqiliang 5 months ago
parent
commit
e46f7887df

+ 1 - 1
.idea/deploymentTargetDropDown.xml

@@ -12,6 +12,6 @@
         </deviceKey>
       </Target>
     </targetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2025-12-28T07:29:21.986098Z" />
+    <timeTargetWasSelectedWithDropDown value="2026-05-25T02:29:55.281249900Z" />
   </component>
 </project>

+ 1 - 0
.idea/gradle.xml

@@ -8,6 +8,7 @@
         <option name="distributionType" value="DEFAULT_WRAPPED" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="gradleHome" value="$PROJECT_DIR$/../../../Application/gradle/gradle-4.2.1" />
+        <option name="gradleJvm" value="11" />
         <option name="modules">
           <set>
             <option value="$PROJECT_DIR$" />

+ 2 - 2
app/build.gradle

@@ -8,8 +8,8 @@ android {
         applicationId "com.example.jhpapp"
         minSdk 22
         targetSdk 31
-        versionCode 5
-        versionName "2.9"
+        versionCode 6
+        versionName "3.0"
 
         testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
         ndk {  abiFilters "armeabi","armeabi-v7a","x86"}

+ 14 - 2
app/src/main/java/com/example/jhpapp/MainActivity.java

@@ -33,6 +33,8 @@ import com.google.android.exoplayer2.MediaItem;
 import com.google.android.exoplayer2.PlaybackException;
 import com.google.android.exoplayer2.Player;
 import com.google.android.exoplayer2.SimpleExoPlayer;
+import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
+import com.google.android.exoplayer2.upstream.DefaultHttpDataSource;
 import pl.droidsonroids.gif.GifImageView;
 
 public class MainActivity extends BaseActivity {
@@ -315,7 +317,17 @@ public class MainActivity extends BaseActivity {
 
     public void initMedAudio(){
         if (player == null) {
-            player = new SimpleExoPlayer.Builder(this).build();
+            // 配置 HTTP 层超时,避免网络波动时播放器无限期卡在缓冲
+            DefaultHttpDataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
+            dataSourceFactory.setConnectTimeoutMs(10_000);  // 连接超时 10s
+            dataSourceFactory.setReadTimeoutMs(20_000);     // 读取超时 20s
+
+            DefaultMediaSourceFactory mediaSourceFactory =
+                new DefaultMediaSourceFactory(dataSourceFactory);
+
+            player = new SimpleExoPlayer.Builder(this)
+                .setMediaSourceFactory(mediaSourceFactory)
+                .build();
             // 仅添加一次全局监听器
             player.addListener(globalPlayerListener);
         }
@@ -444,4 +456,4 @@ public class MainActivity extends BaseActivity {
             webIDs = null;
         }
     }
-}
+}

+ 2 - 1
gradle.properties

@@ -16,4 +16,5 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
 # https://developer.android.com/topic/libraries/support-library/androidx-rn
 android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
-android.enableJetifier=true
+android.enableJetifier=true
+org.gradle.java.home=D:\\Application\\androidstudio\\jre

+ 3 - 3
gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
-#Sat May 31 14:53:20 CST 2025
+#Tue May 26 08:52:00 CST 2026
 distributionBase=GRADLE_USER_HOME
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
 distributionPath=wrapper/dists
-zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
 zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists