Hello,
Event handlers only can be added or removed within the Game1 class where the event is declared.
public class Game1
{
public event EventHandler OnLoadingContent;
public void SomeMethod()
{
// Subscribe to the event
this.OnLoadingContent += YourEventHandlerMethod;
// Unsubscribe from the event
this.OnLoadingContent -= YourEventHandlerMethod;
}
private void YourEventHandlerMethod(object sender, EventArgs e)
{
// Event handling logic
}
}
Based on your previous link, do you want to popup dialog and play the video by Game1 class in the Options.cs
?
If so, you can add an attribute in the Game1's constructor. Then create a method(called ShowTheVideo for testing) to popup a dialog and play the video. By the way, please remove the await CrossMediaManager.Current.Play("https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
in the LoadContent method, and add ShowTheVideo();
directly.
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Activity1 activity1;
public Game1(Activity1 activity1)
{
this.activity1 = activity1;
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
public async void ShowTheVideo()
{
VideoDialog customDialog = new VideoDialog(activity1);
customDialog.SetCancelable(false);
customDialog.Show();
await CrossMediaManager.Current.Play("https://sec.ch9.ms/ch9/5d93/a1eab4bf-3288-4faf-81c4-294402a85d93/XamarinShow_mid.mp4");
CrossMediaManager.Current.MediaItemFinished += (s, e) =>
{
customDialog.Cancel();
};
}
protected override async void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// await CrossMediaManager.Current.Play("https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
ShowTheVideo();
}
}
In the end, you can call game1.ShowTheVideo();
in the Load
method of Options
class.
public class Options
{
private Game1 game1;
GraphicsDevice graphicsDevice;
public Options(Game1 game, GraphicsDevice device)
{
game1 = game;
graphicsDevice = device;
}
public async void Load(ContentManager content)
{
game1.ShowTheVideo();
// await CrossMediaManager.Current.Play("https://videos.pexels.com/video-files/7356431/7356431-hd_1280_720_25fps.mp4");
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.