2017-08-15 3 views
1

iOS用のXamarinフォームでは、ビデオコントロールを表示するContentPage用のカスタムレンダラーがあります。私のXamarin Formsアプリケーションでは、このカスタムContentPageがNavigationPage内に表示されます。 特定のメッセージがMQTT経由で入ったときにビデオ画面を開いておきたいです。バックグラウンドスレッドからコンテンツページをプッシュアプ​​リをフリーズ

メイン画面のリンクをクリックしてビデオページを開くと、期待どおりに開きます。コンソール文とブレークポイントのためMQTT経由でメッセージを受け取り、Navigation.PushModalAsync()を呼び出していることは分かっています。ただし、カスタムレンダリングされたページは表示されず、PushModalAsyncを呼び出した後に毎回私のアプリのUIがフリーズします。

Navigation.PushModalAsync()を私のアプリのバックグラウンドでMQTT通知を受信したことに基づいてトリガーする必要がありますか?

ViewRoomsPage.axml.cs:

[XamlCompilation(XamlCompilationOptions.Compile)] 
public partial class ViewRoomsPage : ContentPage 
{ 
    public ViewRoomsPage() 
    { 
     InitializeComponent(); 
    } 

    public string StreamUri { get; set; } 
} 

ViewRoomsPage.axml:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="MyForms.Pages.ViewRoomsPage"> 
<ContentPage.Content> 
</ContentPage.Content> 

VideoViewerRenderer.cs(ビデオコードが除去;また、これは空白の赤色画面を表示する必要がそれ。メイン画面のボタンから起動すると機能します)

[assembly: ExportRenderer(typeof(ViewRoomsPage), typeof(ViewRoomsRenderer))] 
namespace MyForms.IOS.NativeImplementations 
{ 
    public class ViewRoomsRenderer : PageRenderer 
    { 
     private IJKFFMoviePlayerController _playerController; 

     protected override void OnElementChanged(VisualElementChangedEventArgs e) 
     { 

      base.OnElementChanged(e); 

      if (e.OldElement != null || Element == null) 
      { 
       return; 
      } 

      e.NewElement.BackgroundColor = Color.Red; 
     } 
    } 
} 

方法MQTTメッセージApp.xaml.csで

public void PushViewRooms() 
    { 
     Device.BeginInvokeOnMainThread(async() => 
     { 
      await Application.Current.MainPage.Navigation.PushModalAsync(new ViewRoomsPage()); 
     }); 
    } 

を受けるからトリガ:

public partial class App : Application 
{ 
    public App() 
    { 
     SetupDependencies(); // using StructureMap 
     Manager = DependencyContainer.Resolve<IMqttManager>(); 
     Manager.Connect();    

     InitializeComponent(); 

     var mainPage = new MainPage(); 
     MainPage = new NavigationPage(mainPage); 
    } 
} 
+0

ナビゲーションはメインスレッドで行う必要があります。 –

+0

Right、したがって、 'Device.BeginInvokeOnMainThread()'のNavigation.Push呼び出しをラップします。 – Cass

+0

どこから 'PushViewRooms()'が呼び出されますか? –

答えて

0

問題がで実行されているコードの別のセクションでトリガさTask.WaitAll()によって生じるデッドロックましたバックグラウンド。

レンダラーが設定された方法で何かではなかったことを健全性チェックに役立ててくれたすべての人に感謝します。

関連する問題