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 duplicate callback #107

Open
wants to merge 8 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
4 changes: 2 additions & 2 deletions packages/audiofileplayer/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
compileSdkVersion 31

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -40,5 +40,5 @@ android {

dependencies {
implementation 'androidx.core:core:1.0.0'
implementation 'androidx.media:media:1.0.0'
implementation 'androidx.media:media:1.3.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Flutter audio file player plugin.
Expand Down Expand Up @@ -347,14 +348,17 @@ private void onLoad(MethodCall call, Result result) {
// Note that this will throw an exception on invalid URL or lack of network connectivity.
RemoteManagedMediaPlayer newPlayer =
new RemoteManagedMediaPlayer(audioId, remoteUrl, this, looping, playInBackground);
final AtomicBoolean remoteLoad = new AtomicBoolean(false);
newPlayer.setOnRemoteLoadListener(
(success) -> {
if (success) {
handleDurationForPlayer(newPlayer, audioId);
result.success(null);
} else {
mediaPlayers.remove(audioId);
result.error(ERROR_CODE, "Remote URL loading failed for URL: " + remoteUrl, null);
if (remoteLoad.compareAndSet(false, true)) {
if (success) {
handleDurationForPlayer(newPlayer, audioId);
result.success(null);
} else {
mediaPlayers.remove(audioId);
result.error(ERROR_CODE, "Remote URL loading failed for URL: " + remoteUrl, null);
}
}
});
// Add player to data structure immediately; will be removed if async loading fails.
Expand Down Expand Up @@ -509,16 +513,16 @@ public void onActivityDestroyed(Activity activity) {
@Override
public void onConnected() {
Log.i(TAG, "ConnectionCallback.onConnected");
try {
// try {
MediaSessionCompat.Token token = mediaBrowser.getSessionToken();
mediaController = new MediaControllerCompat(activity, token);
MediaControllerCompat.setMediaController(activity, mediaController);
mediaController.registerCallback(controllerCallback);
AudiofileplayerService.instance.setPendingIntentActivity(activity);
AudiofileplayerService.instance.setListener(AudiofileplayerPlugin.this);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
// } catch (RemoteException e) {
// throw new RuntimeException(e);
// }
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void setPendingIntentActivity(Activity activity) {
Context context = activity.getApplicationContext();
Intent intent = new Intent(context, activity.getClass());
PendingIntent pendingIntent =
PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.getActivity(context, 99, intent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT);
mediaSession.setSessionActivity(pendingIntent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"audiofileplayer","path":"/Users/dengxianshun/pluginspace/flutter.plugins/packages/audiofileplayer/","dependencies":[]},{"name":"path_provider","path":"/Users/dengxianshun/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider-2.0.3/","dependencies":[]}],"android":[{"name":"audiofileplayer","path":"/Users/dengxianshun/pluginspace/flutter.plugins/packages/audiofileplayer/","dependencies":[]},{"name":"path_provider","path":"/Users/dengxianshun/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider-2.0.3/","dependencies":[]}],"macos":[{"name":"path_provider_macos","path":"/Users/dengxianshun/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider_macos-2.0.2/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/dengxianshun/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider_linux-2.0.2/","dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"/Users/dengxianshun/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/path_provider_windows-2.0.3/","dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"audiofileplayer","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_linux","path_provider_macos","path_provider_windows"]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_macos","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2021-09-10 17:27:37.935922","version":"2.5.0"}
18 changes: 18 additions & 0 deletions packages/audiofileplayer/example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
#

Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.description = <<-DESC
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
DESC
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => '[email protected]' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.vendored_frameworks = 'Flutter.framework'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/dengxianshun/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/dengxianshun/pluginspace/flutter.plugins/packages/audiofileplayer/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/dengxianshun/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
997AD79126329BE4001D2FCD /* ios in Resources */ = {isa = PBXBuildFile; fileRef = 997AD79026329BE4001D2FCD /* ios */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -48,6 +49,7 @@
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
997AD79026329BE4001D2FCD /* ios */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ios; path = ../../../ios; sourceTree = "<group>"; };
C1B130F899C72F55F2976942 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
EC8F38AE54ABD5EB70CDAE54 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -107,6 +109,7 @@
97C146F01CF9000F007C117D /* Runner */ = {
isa = PBXGroup;
children = (
997AD79026329BE4001D2FCD /* ios */,
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */,
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */,
97C146FA1CF9000F007C117D /* Main.storyboard */,
Expand Down Expand Up @@ -150,6 +153,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
819ED315A953D3AAA113DCE2 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -203,6 +207,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
997AD79126329BE4001D2FCD /* ios in Resources */,
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */,
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */,
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */,
Expand Down Expand Up @@ -246,6 +251,24 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
819ED315A953D3AAA113DCE2 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Loading