MrJai / flutter_to_airplay

Flutter plugin that offers two widgets, one to play a video for a given URL or file path using native AVPlayer and second with an option to airplay it on available Apple devices.
MIT License
30 stars 24 forks source link

Is it possible to use AirPlayRoutePickerView() with other video player #5

Closed expertdevs closed 4 years ago

expertdevs commented 4 years ago

Hello, Thanks to make this plugin I really need this. But I want to know Is it possible to use AirPlayRoutePickerView() with other video player (like flick_video_player) or if possible please add video controllers and screen orientation functionality.

MrJai commented 4 years ago

Hi, theoretically it should be, as it is an independent widget that can be integrated anywhere, but it still needs to be tested in such cases. Do let me know if it works for you or not and I will be available to improve it if there is an issue.

Regarding further support of video controllers and orientation functionality, please give me time, I work on these over the weekends only, but I will try to check it out during the week as well. In the meantime, if you want to contribute, please feel free to open a PR and I will review that.

Thank you for your comment.

expertdevs commented 4 years ago

I tried to integrate it independently and it worked 1st time but 2nd time when i played my video app crashed with any logs.

MrJai commented 4 years ago

Can you share the logs or the PR, so that I can review and fix it? It will be difficult to fix without reproducing.

expertdevs commented 4 years ago

I tried with xCode and got this

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /path/flutter_sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_to_airplay-1.0.2/ios/Classes/FlutterAVPlayer.swift, line 26

Line 26: let filePath = arguments["file"] as! String

MrJai commented 4 years ago

Okay, let me fix it. Can you share the widget code as well? how you are creating FlutterAVPlayer widget.

expertdevs commented 4 years ago

I used flick_video_player because I need to play video in landscape mode

MrJai commented 4 years ago

I just pushed a fix to the master branch. I will submit a new version to pub.dev in a few minutes.

JigarKotak7 commented 4 years ago

Any update on above? As I am still facing the same issue.

Fatal error: Unexpectedly found nil while unwrapping an Optional value

JigarKotak7 commented 4 years ago

I have found a workaround but you can find a proper solution to it, I was going through the code and using breakpoints realized that the first time I build AirPlayRoutePickerView() Widget it builds it properly and when I try to build it second time it was trying to build FlutterAVPlayer() Widget instead and it was null so the app was crashing. So in the below file you see if viewId == 1 it build the AirPlayRoutePickerView() else it would build FlutterAVPlayer() Widget and when I try to load the page second time the viewId is incremented, for now I have changed it to if viewId >= 1 and it works for my purpose but you can implement a proper fix for it.

Thank you Jigar Kotak

// // SharePlatformViewFactory.swift // flutter_to_airplay // // Created by Junaid Rehmat on 22/08/2020. // import Foundation import Flutter

class SharePlatformViewFactory: NSObject, FlutterPlatformViewFactory { var _messenger : FlutterBinaryMessenger

init(messenger: FlutterBinaryMessenger & NSObjectProtocol) {
    _messenger = messenger
}

func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
    if viewId == 1 {
        let pickerView = FlutterRoutePickerView(frame: frame, viewIdentifier: viewId, arguments: args as! Dictionary<String, Any>, binaryMessenger: _messenger)
        return pickerView
    }
    else
    {
        let pickerView = FlutterAVPlayer(frame: frame, viewIdentifier: viewId, arguments: args as! Dictionary<String, Any>, binaryMessenger: _messenger)
        return pickerView
    }
}

func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
    return FlutterStandardMessageCodec.sharedInstance()
}

}

MrJai commented 4 years ago

Thank you @expertdevs and @JigarKotak7. I have published version 1.0.4 and that will fix all of the crash issues. Please feel free to comment if you notice any further crashes. I will try to be more responsive now.