Bläddra i källkod

解决编译问题

ykrank 5 år sedan
förälder
incheckning
cd46619a58

+ 0
- 1
android/build.gradle Visa fil

@@ -45,7 +45,6 @@ android {
45 45
 
46 46
 dependencies {
47 47
     implementation fileTree(dir: 'libs', include: ['*.jar'])
48
-    implementation 'com.android.support:appcompat-v7:27.1.1'
49 48
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
50 49
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
51 50
 }

android/src/main/java/com/fgodt/mixplayer/Core.java → android/src/main/java/com/shuangyubang/mofun_flutter_plugin_video/mixplayer/Core.java Visa fil

@@ -1,11 +1,7 @@
1
-package com.fgodt.mixplayer;
1
+package com.shuangyubang.mofun_flutter_plugin_video.mixplayer;
2 2
 
3 3
 import android.util.Log;
4 4
 import android.view.Surface;
5
-import android.view.SurfaceHolder;
6
-
7
-
8
-import java.util.Arrays;
9 5
 
10 6
 /**
11 7
  * Created by rt-zl on 2019/2/15.

android/src/main/java/com/fgodt/mixplayer/Player.java → android/src/main/java/com/shuangyubang/mofun_flutter_plugin_video/mixplayer/Player.java Visa fil

@@ -1,4 +1,4 @@
1
-package com.fgodt.mixplayer;
1
+package com.shuangyubang.mofun_flutter_plugin_video.mixplayer;
2 2
 
3 3
 import android.content.Context;
4 4
 

android/src/main/java/com/fgodt/mixplayer/Render.java → android/src/main/java/com/shuangyubang/mofun_flutter_plugin_video/mixplayer/Render.java Visa fil

@@ -1,4 +1,4 @@
1
-package com.fgodt.mixplayer;
1
+package com.shuangyubang.mofun_flutter_plugin_video.mixplayer;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.media.AudioFormat;
@@ -28,7 +28,7 @@ public class Render extends VideoRender {
28 28
 
29 29
     public int mixUpdateAudio(byte[] data, int size, double pts) {
30 30
         playTime = pts;
31
-        synchronized (audioBuf) {
31
+        synchronized (audioBufLock) {
32 32
             if (audioBufLen - audioHas < size) {
33 33
                 return -1;
34 34
             }
@@ -93,6 +93,7 @@ public class Render extends VideoRender {
93 93
 
94 94
     AudioTrack audioTrack;
95 95
 
96
+    final Object audioBufLock = new Object();
96 97
     byte[] audioBuf;
97 98
     long totalAudioBuf;
98 99
     int audioHas;
@@ -105,75 +106,74 @@ public class Render extends VideoRender {
105 106
 
106 107
     private void initAudioTrack() {
107 108
         silencBuf = new byte[4096];
108
-        audioBuf = new byte[audioBufLen];
109
+        synchronized (audioBufLock) {
110
+            audioBuf = new byte[audioBufLen];
111
+        }
109 112
         audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, asample,
110 113
                 AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, audioBufLen, AudioTrack.MODE_STREAM);
111 114
         play = true;
112
-        new Thread(new Runnable() {
113
-            @Override
114
-            public void run() {
115
-                int wsize = 1024;
116
-                long posPre = 0;
117
-                boolean needUpdate = false;
118
-                int retryCount = 0;
119
-                while (play) {
120
-                    synchronized (audioBuf) {
121
-                        long pos = audioTrack.getPlaybackHeadPosition();
122
-                        // 16bit 2channels = 4 Byte
123
-                        pos *= 4;
124
-                        pos -= silenceLen;
125
-                        if (posPre != pos) {
126
-                            posPre = pos;
127
-                            retryCount = 0;
128
-                        } else {
129
-                            if (retryCount > 5)
130
-                                needUpdate = true;
131
-                            retryCount++;
115
+        new Thread(() -> {
116
+            int wsize = 1024;
117
+            long posPre = 0;
118
+            boolean needUpdate = false;
119
+            int retryCount = 0;
120
+            while (play) {
121
+                synchronized (audioBufLock) {
122
+                    long pos = audioTrack.getPlaybackHeadPosition();
123
+                    // 16bit 2channels = 4 Byte
124
+                    pos *= 4;
125
+                    pos -= silenceLen;
126
+                    if (posPre != pos) {
127
+                        posPre = pos;
128
+                        retryCount = 0;
129
+                    } else {
130
+                        if (retryCount > 5)
131
+                            needUpdate = true;
132
+                        retryCount++;
133
+                    }
134
+                    if (audioHas >= wsize && totalAudioBuf - pos < audioBufLen || pos <= 0 || needUpdate) {
135
+                        needUpdate = false;
136
+                        int len = audioBufLen - audioRPos;
137
+                        len = len > wsize ? wsize : len;
138
+                        int ret = audioTrack.write(audioBuf, audioRPos, len);
139
+                        audioRPos += ret;
140
+                        audioHas -= ret;
141
+                        totalAudioBuf += ret;
142
+                        if (audioRPos == audioBufLen) {
143
+                            audioRPos = 0;
132 144
                         }
133
-                        if (audioHas >= wsize && totalAudioBuf - pos < audioBufLen || pos <= 0 || needUpdate) {
134
-                            needUpdate = false;
135
-                            int len = audioBufLen - audioRPos;
136
-                            len = len > wsize ? wsize : len;
137
-                            int ret = audioTrack.write(audioBuf, audioRPos, len);
138
-                            audioRPos += ret;
139
-                            audioHas -= ret;
140
-                            totalAudioBuf += ret;
141
-                            if (audioRPos == audioBufLen) {
142
-                                audioRPos = 0;
145
+                    } else {
146
+                        //    if (pos == totalAudioBuf && audioHas < wsize){
147
+                        //        int c = audioTrack.write(silencBuf,0,2048);
148
+                        //        silenceLen +=c;
149
+                        //    }
150
+                    }
151
+                    if (ispause) {
152
+                        if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PAUSED) {
153
+                            audioTrack.pause();
154
+                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
155
+                                audioTrack.setVolume(0);
156
+                            } else {
157
+                                audioTrack.setStereoVolume(0, 0);
143 158
                             }
144
-                        } else {
145
-                            //    if (pos == totalAudioBuf && audioHas < wsize){
146
-                            //        int c = audioTrack.write(silencBuf,0,2048);
147
-                            //        silenceLen +=c;
148
-                            //    }
149 159
                         }
150
-                        if (ispause) {
151
-                            if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PAUSED) {
152
-                                audioTrack.pause();
153
-                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
154
-                                    audioTrack.setVolume(0);
155
-                                } else {
156
-                                    audioTrack.setStereoVolume(0, 0);
157
-                                }
158
-                            }
159
-                        } else {
160
-                            if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
161
-                                audioTrack.play();
162
-                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
163
-                                    audioTrack.setVolume(volume);
164
-                                } else {
165
-                                    audioTrack.setStereoVolume(volume, volume);
166
-                                }
160
+                    } else {
161
+                        if (audioTrack.getPlayState() != AudioTrack.PLAYSTATE_PLAYING) {
162
+                            audioTrack.play();
163
+                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
164
+                                audioTrack.setVolume(volume);
165
+                            } else {
166
+                                audioTrack.setStereoVolume(volume, volume);
167 167
                             }
168 168
                         }
169 169
                     }
170
-                    try {
171
-                        sleep(3);
172
-                    } catch (Exception ex) {
173
-                    }
174 170
                 }
175
-                Log.d("mixplayer", "audio close");
171
+                try {
172
+                    sleep(3);
173
+                } catch (Exception ignored) {
174
+                }
176 175
             }
176
+            Log.d("mixplayer", "audio close");
177 177
         }).start();
178 178
         audioTrack.play();
179 179
     }

android/src/main/java/com/fgodt/mixplayer/VideoRender.java → android/src/main/java/com/shuangyubang/mofun_flutter_plugin_video/mixplayer/VideoRender.java Visa fil

@@ -1,4 +1,4 @@
1
-package com.fgodt.mixplayer;
1
+package com.shuangyubang.mofun_flutter_plugin_video.mixplayer;
2 2
 
3 3
 
4 4
 

android/src/main/java/com/fgodt/mixplayer/mixPlayerCallBack.java → android/src/main/java/com/shuangyubang/mofun_flutter_plugin_video/mixplayer/mixPlayerCallBack.java Visa fil

@@ -1,4 +1,4 @@
1
-package com.fgodt.mixplayer;
1
+package com.shuangyubang.mofun_flutter_plugin_video.mixplayer;
2 2
 
3 3
 public interface mixPlayerCallBack{
4 4
     public int mix_call(String name, byte[] data, int len);

+ 2
- 4
android/src/main/kotlin/com/shuangyubang/mofun_flutter_plugin_video/MofunRealVideoView.kt Visa fil

@@ -4,13 +4,11 @@ import android.content.Context
4 4
 import android.media.AudioFormat
5 5
 import android.media.AudioRecord
6 6
 import android.media.MediaRecorder
7
-import android.os.Environment
8
-import android.view.Gravity
9 7
 import android.view.View
10 8
 import android.widget.FrameLayout
11 9
 import android.widget.Toast
12
-import com.fgodt.mixplayer.Player
13
-import com.fgodt.mixplayer.mixPlayerCallBack
10
+import com.shuangyubang.mofun_flutter_plugin_video.mixplayer.Player
11
+import com.shuangyubang.mofun_flutter_plugin_video.mixplayer.mixPlayerCallBack
14 12
 
15 13
 class MofunRealVideoView(val context: Context) : mixPlayerCallBack {
16 14
 

+ 6
- 0
example/android/app/build.gradle Visa fil

@@ -44,6 +44,7 @@ android {
44 44
         versionCode flutterVersionCode.toInteger()
45 45
         versionName flutterVersionName
46 46
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
47
+
47 48
     }
48 49
 
49 50
     buildTypes {
@@ -59,6 +60,11 @@ flutter {
59 60
     source '../..'
60 61
 }
61 62
 
63
+tasks.withType(JavaCompile) {
64
+    options.encoding = 'UTF-8'
65
+    options.compilerArgs << '-Xlint:unchecked,deprecation'
66
+}
67
+
62 68
 dependencies {
63 69
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
64 70
     testImplementation 'junit:junit:4.12'

+ 1
- 0
example/android/gradle.properties Visa fil

@@ -1 +1,2 @@
1 1
 org.gradle.jvmargs=-Xmx1536M
2
+android.useAndroidX=true

+ 1
- 1
example/pubspec.lock Visa fil

@@ -82,7 +82,7 @@ packages:
82 82
     source: hosted
83 83
     version: "1.5.0"
84 84
   permission_handler:
85
-    dependency: "direct main"
85
+    dependency: transitive
86 86
     description:
87 87
       name: permission_handler
88 88
       url: "https://pub.flutter-io.cn"

+ 0
- 1
example/pubspec.yaml Visa fil

@@ -12,7 +12,6 @@ dependencies:
12 12
   # The following adds the Cupertino Icons font to your application.
13 13
   # Use with the CupertinoIcons class for iOS style icons.
14 14
   cupertino_icons: ^0.1.2
15
-  permission_handler: ^3.0.0
16 15
 
17 16
 dev_dependencies:
18 17
   flutter_test: