Skip to content

Commit 5a688bd

Browse files
lsakeeSangwook123
authored andcommitted
[delete] #62 delete unnecessary code
1 parent 3fb71c8 commit 5a688bd

File tree

1 file changed

+0
-97
lines changed

1 file changed

+0
-97
lines changed

feature/upload/src/main/java/com/record/upload/extension/UploadExtension.kt

-97
Original file line numberDiff line numberDiff line change
@@ -167,100 +167,3 @@ fun formatDuration(durationMillis: Long): String {
167167
return String.format("%d:%02d", minutes, seconds)
168168
}
169169

170-
// fun uploadFileToS3PresignedUrl(
171-
// presignedUrl: String,
172-
// file: File,
173-
// callback: (Boolean, String) -> Unit,
174-
// ) {
175-
// val client = OkHttpClient()
176-
// val mediaType = "application/octet-stream".toMediaTypeOrNull()
177-
// val requestBody = RequestBody.create(mediaType, file)
178-
//
179-
// val request = Request.Builder()
180-
// .url(presignedUrl)
181-
// .put(requ estBody)
182-
// .build()
183-
// client.newCall(request).enqueue(
184-
// object : okhttp3.Callback {
185-
// override fun onFailure(call: okhttp3.Call, e: IOException) {
186-
// callback(false, "Upload failed: ${e.message}")
187-
// }
188-
//
189-
// override fun onResponse(call: okhttp3.Call, response: okhttp3.Response) {
190-
// if (response.isSuccessful) {
191-
// callback(true, "${response.request.url}")
192-
// } else {
193-
// callback(false, "Upload failed: ${response.message}")
194-
// }
195-
// }
196-
// },
197-
// )
198-
// }
199-
200-
fun uploadFileToS3ThumbnailPresignedUrl(
201-
context: Context,
202-
presignedUrl: String,
203-
file: File,
204-
callback: (Boolean, String) -> Unit,
205-
) {
206-
val videoPath = file.absolutePath
207-
val outputImagePath = File(context.cacheDir, file.name)
208-
getVideoFrameAt1Sec(videoPath, outputImagePath.absolutePath)
209-
val client = OkHttpClient()
210-
val mediaType = "application/octet-stream".toMediaTypeOrNull()
211-
val requestBody = RequestBody.create(mediaType, outputImagePath)
212-
213-
val request = Request.Builder()
214-
.url(presignedUrl)
215-
.put(requestBody)
216-
.build()
217-
client.newCall(request).enqueue(
218-
object : okhttp3.Callback {
219-
override fun onFailure(call: okhttp3.Call, e: IOException) {
220-
callback(false, "Upload failed: ${e.message}")
221-
}
222-
223-
override fun onResponse(call: okhttp3.Call, response: okhttp3.Response) {
224-
if (response.isSuccessful) {
225-
callback(true, "${response.request.url}")
226-
} else {
227-
callback(false, "Upload failed: ${response.message}")
228-
}
229-
}
230-
},
231-
)
232-
}
233-
234-
fun getVideoFrameAt1Sec(videoPath: String, outputImagePath: String) {
235-
val retriever = MediaMetadataRetriever()
236-
try {
237-
retriever.setDataSource(videoPath)
238-
val timeUs = 1 * 1000000
239-
val bitmap: Bitmap? =
240-
retriever.getFrameAtTime(timeUs.toLong(), MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
241-
242-
if (bitmap != null) {
243-
saveBitmapAsJpeg(bitmap, outputImagePath)
244-
}
245-
} catch (e: Exception) {
246-
e.printStackTrace()
247-
} finally {
248-
retriever.release()
249-
}
250-
}
251-
252-
fun saveBitmapAsJpeg(bitmap: Bitmap, outputPath: String) {
253-
var out: FileOutputStream? = null
254-
try {
255-
out = FileOutputStream(outputPath)
256-
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out)
257-
} catch (e: IOException) {
258-
e.printStackTrace()
259-
} finally {
260-
try {
261-
out?.close()
262-
} catch (e: IOException) {
263-
e.printStackTrace()
264-
}
265-
}
266-
}

0 commit comments

Comments
 (0)