0

以下のコードを検討してください。期待どおりに動作します - MPMoviePlayerDidExitFullscreenNotification 通知が送信され、ClosePlayer メソッドが呼び出されます。

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.MediaPlayer;
using MonoTouch.UIKit;

public partial class PlayerViewController : MPMoviePlayerController
{
    public PlayerViewController() : base()
    {
        NSNotificationCenter.DefaultCenter.AddObserver("MPMoviePlayerDidExitFullscreenNotification", this.ClosePlayer);
    }

    private void ClosePlayer(NSNotification notification)
    {
        // Do something..
    }
}

しかし、このデザインは私には奇妙に思えます。以下のようなもっと単純なことができないだろうかと思います:

this.MPMoviePlayerDidExitFullscreenNotification += this.ClosePlayer;

クラス自体によって起動されるイベントをリッスンするために NSNotificationCenter を通過する必要があるのは、非常に不自然に思えます。または、何か不足していますか?

また、ハードコードされた文字列以外の方法で通知タイプ (例: MPMoviePlayerDidExitFullscreenNotification) を指定することは可能ですか?

前もって感謝します :)

免責事項: 私は MonoTouch の完全な初心者であり、.NET のバックグラウンドを持っているため、非常に奇妙に感じることがあります。

4

1 に答える 1

2

MPMoviePlayerController に使用できる静的プロパティがあることを偶然知りました。

MPMoviePlayerController.Notifications.ObserveDidExitFullscreen(this.ClosePlayer);
于 2013-07-14T14:28:27.717 に答える