feat: "share url" in audio player
Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
c2888a70d3
commit
e1a001ce5c
|
|
@ -1,8 +1,11 @@
|
|||
package chat.revolt.components.media
|
||||
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
import android.provider.MediaStore
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
|
|
@ -63,6 +66,10 @@ fun AudioPlayer(
|
|||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
val activityLauncher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) {}
|
||||
|
||||
val player = remember {
|
||||
ExoPlayer.Builder(context).build().apply {
|
||||
setMediaItem(MediaItem.fromUri(url))
|
||||
|
|
@ -147,6 +154,20 @@ fun AudioPlayer(
|
|||
}
|
||||
}
|
||||
|
||||
fun shareUrl() {
|
||||
showMenu.value = false
|
||||
|
||||
coroutineScope.launch {
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = "text/plain"
|
||||
putExtra(Intent.EXTRA_TEXT, url)
|
||||
}
|
||||
|
||||
val shareIntent = Intent.createChooser(intent, null)
|
||||
activityLauncher.launch(shareIntent)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
if (currentTime.value != player.currentPosition && player.isPlaying) {
|
||||
|
|
@ -265,7 +286,14 @@ fun AudioPlayer(
|
|||
Text(text = stringResource(R.string.media_viewer_save))
|
||||
}
|
||||
)
|
||||
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
shareUrl()
|
||||
},
|
||||
text = {
|
||||
Text(text = stringResource(R.string.media_viewer_share_url))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue