Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Kotlin build problem #145

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 @@ -143,7 +143,7 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl
return when (intent.action) {
Intent.ACTION_SEND -> {
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
val path = FileDirectory.getAbsolutePath(applicationContext, uri)
val path = uri?.let{ FileDirectory.getAbsolutePath(applicationContext, it) }
if (path != null) {
val type = getMediaType(path)
val thumbnail = getThumbnail(path, type)
Expand Down Expand Up @@ -204,7 +204,7 @@ class ReceiveSharingIntentPlugin : FlutterPlugin, ActivityAware, MethodCallHandl
if (type != MediaType.VIDEO) return null // get duration for video only
val retriever = MediaMetadataRetriever()
retriever.setDataSource(path)
val duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION).toLongOrNull()
val duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toLongOrNull()
retriever.release()
return duration
}
Expand Down
3 changes: 2 additions & 1 deletion ios/Classes/SwiftReceiveSharingIntentPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ public class SwiftReceiveSharingIntentPlugin: NSObject, FlutterPlugin, FlutterSt
guard let path = getAbsolutePath(for: $0.path) else {
return nil
}
return SharedMediaFile.init(path: $0.path, thumbnail: nil, duration: nil, type: $0.type)
let pathWithoutPrefix = String($0.path.dropFirst(7))//knock 'file://' off here...
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch is taken from here #141. @LazyDave76 is the author of both patches.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shared media object has a path property which already contains "file://" on iOS.

This results in file not found when looking up the path in iOS because the value looks like "file://file://PathToCopiedFile"

Copy link

@LazyDave76 LazyDave76 Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having 'fixed' this bug in a pretty hacky way - this is probably what it should look like:

Suggested change
let pathWithoutPrefix = String($0.path.dropFirst(7))//knock 'file://' off here...
return SharedMediaFile.init(path: path, thumbnail: nil, duration: nil, type: $0.type)

seems that the path is url encoded though and there are fun times with files with spaces...

return SharedMediaFile.init(path: pathWithoutPrefix, thumbnail: nil, duration: nil, type: $0.type)
}
latestMedia = sharedMediaFiles
if(setInitialData) {
Expand Down