按下快速向前/向后按钮时,代号一个视频在iOS上崩溃

时间:2018-11-01 20:50:17

标签: ios video codenameone

我们有一个用代号“ 1”编写的视频供应应用程序。 我们正在使用 com.codename1.media.MediaPlayer 使用本机播放器组件全屏显示视频。
我们的客户注意到,当您按下快进(>>)按钮或后退按钮(<<)时,视频会将您踢回到应用程序。

播放视频的代码如下所示;

...
private Media video;
...
(on EDT:)
InputStream input = {get video InputStream from path}
video = MediaManager.createMedia(input, "video/mp4", this::videoFinished);
video.setFullScreen(true);
video.setNativePlayerMode(true);
.... 
(after pressing the play button:)
if (video.isPlaying()) {
     video.setTime(0);
    video.pause();
}
video.prepare();
video.play();
...
private void videoFinished() {
    {update UI after video has finished}
}

如果有帮助,我从控制台收集了以下日志;

2018-11-01 15:08:38.290366+1300 Main[2000:481106] [] <<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_None (client: Main)
2018-11-01 15:08:39.058905+1300 Main[2000:481106] [] <<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_Presence (client: Main)
2018-11-01 15:09:00.005725+1300 Main[2000:481106] Status bar could not find cached time string image. Rendering in-process.
2018-11-01 15:09:00.144446+1300 Main[2000:481106] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
"<NSAutoresizingMaskLayoutConstraint:0x10eb09790 h=-&- v=-&- _UIBackdropContentView:0x108d4a310.midY == _UIBackdropView:0x108d59fb0.midY   (active)>",
"<NSAutoresizingMaskLayoutConstraint:0x10eb0abd0 h=-&- v=-&- _UIBackdropContentView:0x108d4a310.height == _UIBackdropView:0x108d59fb0.height   (active)>",
"<NSLayoutConstraint:0x10ccf2440 V:|-(0)-[UIStatusBar:0x102922200]   (active, names: '|':_UIBackdropContentView:0x108d4a310 )>",
"<NSLayoutConstraint:0x10ccf24e0 UIStatusBar:0x102922200.height == 20   (active)>",
"<NSLayoutConstraint:0x10ccf2bf0 UIView:0x10cce7e10.top == _UIBackdropView:0x108d59fb0.top + 40   (active)>",
"<NSLayoutConstraint:0x10ccf26e0 V:[UIStatusBar:0x102922200]-(0)-[UIView:0x10cce7e10]   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x10ccf26e0 V:[UIStatusBar:0x102922200]-(0)-[UIView:0x10cce7e10]   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2018-11-01 15:09:00.687662+1300 Main[2000:481106] [] <<<< AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery mode to DiscoveryMode_None (client: Main)

一切都在Android上正常运行。

编辑:

重构代码以使用文件URL代替输入流,但是在iOS上仍然存在相同的错误

编辑:

即使使用网址,这也是一个问题。
这是一个非常简单的测试用例,可以说明问题。

public class MyApplication {

    private Form current;
    private Resources theme;
    private Media video;

    public void init(Object context) {
        // use two network threads instead of one
        updateNetworkThreadCount(2);

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);

        addNetworkErrorListener(err -> {
            // prevent the event from propagating
            err.consume();
            if(err.getError() != null) {
                Log.e(err.getError());
            }
            Log.sendLogAsync();
            Dialog.show("Connection Error", "There was a networking error in the connection to " + err.getConnectionRequest().getUrl(), "OK", null);
        });        
    }

    public void start() {
        if(current != null){
            current.show();
            return;
        }
        Form hi = new Form("Hi World", BoxLayout.y());
        //hi.add(new Label("Hi World"));
        Button play = new Button("Play");
        play.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                playVideo();
            }


        });
        hi.add(play);
        hi.show();
    }

    private void playVideo() {
        try {
            String path = getPath();
            video = MediaManager.createMedia(path, true, null);
            video.setFullScreen(true);
            video.setNativePlayerMode(true);

            video.prepare();
            video.play();
        } catch (IOException ex) {
            Log.e(ex);
        }
    }

    private String getPath() {
        return "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
    }
    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }

    public void destroy() {
    }
}

注意:要在ios上运行此命令,您需要将安全性异常添加到plistInject构建提示中。将其添加到codenameone_settings.properties文件中;

codename1.arg.ios.plistInject=<key>UIRequiresFullScreen</key><true/><key>ITSAppUsesNonExemptEncryption</key><false/><key>NSAppTransportSecurity</key><dict><key>NSExceptionDomains</key><dict><key>commondatastorage.googleapis.com</key><dict><key>NSIncludesSubdomains</key><true/><key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/></dict></dict></dict>

1 个答案:

答案 0 :(得分:1)

使用输入流进行查找可能会有些问题,因为在与本机层通信时我们无法有效地快退/跳过该流。这就是为什么我们总是建议使用接受URL作为参数的版本。您可以使用适用于所有平台的文件URL。