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

add autoLoop param for FlutterAVPlayerView #32

Open
wants to merge 2 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
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
# platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
21 changes: 11 additions & 10 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -226,6 +226,7 @@
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down Expand Up @@ -341,7 +342,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -357,7 +358,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = DF9LCZNCAB;
DEVELOPMENT_TEAM = U6A8MGQQ66;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -372,7 +373,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.junaidrehmat.flutterToAirplayExample;
PRODUCT_BUNDLE_IDENTIFIER = com.junaidsdat.flutterToAirplayExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -427,7 +428,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -476,7 +477,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand All @@ -494,7 +495,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = DF9LCZNCAB;
DEVELOPMENT_TEAM = U6A8MGQQ66;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -509,7 +510,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.junaidrehmat.flutterToAirplayExample;
PRODUCT_BUNDLE_IDENTIFIER = com.junaidsdat.flutterToAirplayExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -525,7 +526,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = DF9LCZNCAB;
DEVELOPMENT_TEAM = U6A8MGQQ66;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -540,7 +541,7 @@
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
PRODUCT_BUNDLE_IDENTIFIER = com.junaidrehmat.flutterToAirplayExample;
PRODUCT_BUNDLE_IDENTIFIER = com.junaidsdat.flutterToAirplayExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
SWIFT_VERSION = 5.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
8 changes: 4 additions & 4 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand All @@ -22,6 +24,8 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand All @@ -43,9 +47,5 @@
<false/>
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/lib/pickFromURL/pick_from_url_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class PickFromURLView extends StatelessWidget {
body: SafeArea(
child: Center(
child: FlutterAVPlayerView(
// filePath: 'assets/videos/butterfly.mp4',
urlString:
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
autoLoop: true,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: Demonstrates how to use the flutter_to_airplay plugin.
publish_to: "none" # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=2.12.0 <4.0.0"
sdk: ">=3.4.3 <4.0.0"

dependencies:
flutter:
Expand Down
36 changes: 27 additions & 9 deletions ios/Classes/FlutterAVPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,57 @@

import Foundation
import AVKit
import AVFoundation
import MediaPlayer
import Flutter

class FlutterAVPlayer: NSObject, FlutterPlatformView {
private var _flutterAVPlayerViewController : AVPlayerViewController;

private var looper : AVPlayerLooper?
private var playerItem: AVPlayerItem?

init(frame:CGRect,
viewIdentifier: CLongLong,
arguments: Dictionary<String, Any>,
binaryMessenger: FlutterBinaryMessenger) {
let autoLoop = arguments["autoLoop"] as? Bool ?? false

_flutterAVPlayerViewController = AVPlayerViewController()
_flutterAVPlayerViewController.viewDidLoad()

let queuePlayer = AVQueuePlayer()

if let urlString = arguments["url"] {
let item = AVPlayerItem(url: URL(string: urlString as! String)!)
_flutterAVPlayerViewController.player = AVPlayer(playerItem: item)
let url = URL(string: urlString as! String)!
playerItem = AVPlayerItem(url: url)
} else if let filePath = arguments["file"] {
let appDelegate = UIApplication.shared.delegate as! FlutterAppDelegate
let vc = appDelegate.window.rootViewController as! FlutterViewController
let lookUpKey = vc.lookupKey(forAsset: filePath as! String)

if let path = Bundle.main.path(forResource: lookUpKey, ofType: nil) {
let item = AVPlayerItem(url: URL(fileURLWithPath: path))
_flutterAVPlayerViewController.player = AVPlayer(playerItem: item)
playerItem = AVPlayerItem(url: URL(fileURLWithPath: path))
} else {
playerItem = AVPlayerItem(url: URL(fileURLWithPath: filePath as! String))
}
else { // Fixed Issue#29
let item = AVPlayerItem(url: URL(fileURLWithPath: filePath as! String))
_flutterAVPlayerViewController.player = AVPlayer(playerItem: item)
}

if let playerItem = playerItem {
if (autoLoop){
looper = AVPlayerLooper(player: queuePlayer, templateItem: playerItem)
_flutterAVPlayerViewController.player = queuePlayer
} else {
_flutterAVPlayerViewController.player = AVPlayer(playerItem: playerItem)
}

_flutterAVPlayerViewController.player?.play()
}
_flutterAVPlayerViewController.player!.play()
}

func view() -> UIView {
return _flutterAVPlayerViewController.view;
}

}

12 changes: 6 additions & 6 deletions ios/Classes/SharePlatformViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ class SharePlatformViewFactory: NSObject, FlutterPlatformViewFactory {
}

func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
let argumens = args as! Dictionary<String, Any>;
if let viewClass = argumens["class"] {
let arguments = args as! Dictionary<String, Any>;
if let viewClass = arguments["class"] {
let vc = viewClass as! String
if vc == "AirplayRoutePicker" {
let pickerView = FlutterRoutePickerView(messenger: _messenger, viewId: viewId, arguments: argumens)
let pickerView = FlutterRoutePickerView(messenger: _messenger, viewId: viewId, arguments: arguments)
return pickerView
}
else if vc == "FlutterAVPlayerView" {
let pickerView = FlutterAVPlayer(frame: frame, viewIdentifier: viewId, arguments: argumens, binaryMessenger: _messenger)
let pickerView = FlutterAVPlayer(frame: frame, viewIdentifier: viewId, arguments: arguments, binaryMessenger: _messenger)
return pickerView
}
}

return UIView() as! FlutterPlatformView
}

func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
return FlutterStandardMessageCodec.sharedInstance()
}
Expand Down
16 changes: 9 additions & 7 deletions lib/src/flutter_avplayer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FlutterAVPlayerView extends StatelessWidget {
Key? key,
this.urlString,
this.filePath,
this.autoLoop = false,
}) : assert(urlString != null || filePath != null),
super(key: key);

Expand All @@ -18,21 +19,22 @@ class FlutterAVPlayerView extends StatelessWidget {

/// Asset name/path for the video file that needs to be played.
final String? filePath;
final bool autoLoop;

/// This function packs the available parameters to be sent to native code.
/// It will check for the URL first, if it is available, then it will be used,
/// otherwise filePath will be used.
/// It is preferred that only one of urlString or filePath is used at a time,
/// if both are provided, application will prioritise urlString.
Map getCreateParams() {
Map params = {
Map<String, dynamic> getCreateParams() {
Map<String, dynamic> params = {
'class': 'FlutterAVPlayerView',
};
if (urlString != null && urlString!.length > 0) {
params['url'] = urlString;
} else {
params['file'] = filePath;
}

params['url'] = urlString;
params['file'] = filePath;
params['autoLoop'] = autoLoop;

return params;
}

Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ homepage: https://github.com/MrJai/flutter_to_airplay
repository: https://github.com/MrJai/flutter_to_airplay

environment:
sdk: ">=2.12.0 <4.0.0"
flutter: ">=1.20.0"
sdk: ">=3.4.3 <4.0.0"

dependencies:
flutter:
Expand Down