Skip to content

Commit e1364d7

Browse files
committed
fix:播放文件后缀,添加保存图片到相册
fix:播放文件后缀,添加保存图片到相册
1 parent 19af77c commit e1364d7

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

android/src/main/java/com/netease/im/RNAppCacheUtilModule.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
package com.netease.im;
22

3+
import android.content.Intent;
4+
import android.net.Uri;
5+
import android.provider.MediaStore;
6+
37
import com.facebook.react.bridge.Promise;
48
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.bridge.ReactContext;
510
import com.facebook.react.bridge.ReactContextBaseJavaModule;
611
import com.facebook.react.bridge.ReactMethod;
712

13+
import java.io.File;
14+
import java.io.FileNotFoundException;
15+
816
/**
917
* Created by dowin on 2017/7/13.
1018
*/
@@ -14,8 +22,10 @@ public class RNAppCacheUtilModule extends ReactContextBaseJavaModule {
1422
private final static String TAG = "AppCacheUtil";//AppCacheUtil.getCacheSize clearCache
1523
private final static String NAME = "AppCacheUtil";
1624

25+
private ReactContext reactContext;
1726
public RNAppCacheUtilModule(ReactApplicationContext reactContext) {
1827
super(reactContext);
28+
this.reactContext = reactContext;
1929
}
2030

2131
@Override
@@ -43,4 +53,20 @@ public void onCleanCache(boolean succeeded) {
4353
}
4454
});
4555
}
56+
@ReactMethod
57+
public void saveImageToAlbum(String filePath, final Promise promise) {
58+
59+
File imageFile = new File(filePath);
60+
if(imageFile.exists()){
61+
try {
62+
MediaStore.Images.Media.insertImage(reactContext.getContentResolver(), imageFile.getAbsolutePath(), "title", "description");
63+
reactContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + imageFile.getAbsolutePath())));
64+
} catch (FileNotFoundException e) {
65+
e.printStackTrace();
66+
}
67+
68+
}
69+
70+
71+
}
4672
}

android/src/main/java/com/netease/im/session/AudioPlayService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void playAudio(Handler handler, ReactContext context, int audioStreamType
5555
LogUtil.i(type, "path:" + filePath);
5656
if (audioStreamType == -1) {
5757
register(context, true);
58-
}else {
58+
} else {
5959
currentAudioStreamType = audioStreamType;
6060
}
6161
if (isPlayingAudio()) {
@@ -80,6 +80,9 @@ public void playAudio(Handler handler, ReactContext context, int audioStreamType
8080
} else if (TextUtils.equals(type, SCHEME_RAW)) {
8181
currentAudioPlayer.setDataSource(AudioPlayerM.Type.raw, filePath);
8282
} else if (TextUtils.equals(type, SCHEME_ASSETS)) {
83+
if (filePath.indexOf(".") == -1) {
84+
filePath = filePath + "." + type;
85+
}
8386
currentAudioPlayer.setDataSource(AudioPlayerM.Type.assets, filePath);
8487
}
8588

0 commit comments

Comments
 (0)