Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ class MediaLoader(
}

private fun maybeSendMediaInfo() {
if (source.isRemote) return
if (source.extension.lowercase() in MediaClassification.rawAudioExtensions) return
if (!source.canProbeMediaInfo) return
scope.launch {
val info = MediaAccessor.getInstance().extractMediaInfo(fileId, projectId)
if (info != null && !bridge.disposed) bridge.sendMediaInfo(info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class EditorMediaSource(val file: VirtualFile) {
val needsTranscoding: Boolean = MediaClassification.needsTranscoding(extension)
val isRemote: Boolean = file.fileSystem !is LocalFileSystem

// Header probing runs host-side, so remote files stay eligible; raw headerless codecs can't be probed.
val canProbeMediaInfo: Boolean = extension !in MediaClassification.rawAudioExtensions

/** Non-null only when the bytes are readable in this process. */
fun localFileOrNull(): File? =
if (!isRemote) runCatching { file.toNioPath().toFile() }.getOrNull()?.takeIf { it.isFile } else null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.twango.jetplay.media

import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.testFramework.LightVirtualFile
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import java.nio.file.Files

Expand Down Expand Up @@ -38,4 +39,16 @@ class EditorMediaSourceTest : BasePlatformTestCase() {
assertFalse(source.needsTranscoding)
assertEquals("mp3", source.extension)
}

// A LightVirtualFile isn't backed by LocalFileSystem, standing in for a Remote Dev / Gateway file.
fun testRemoteFileStaysEligibleForMediaInfo() {
val remote = EditorMediaSource(LightVirtualFile("song.mp3"))
assertTrue("a non-LocalFileSystem file must read as remote", remote.isRemote)
assertTrue("media-info probing runs host-side, so a remote file must stay eligible", remote.canProbeMediaInfo)
}

fun testRawAudioIsNotEligibleForMediaInfo() {
val raw = EditorMediaSource(LightVirtualFile("call.pcmu"))
assertFalse("headerless raw codecs can't be probed", raw.canProbeMediaInfo)
}
}
Loading