Hello,
I noticed that you used SetContentView
twice in the OnCreate
method, and the second time you used Game as View, your MediaPlayer wasn't in that View.
Also, the second time you use SetContentView, the Game's widget is a View, not a ViewGroup. This means that there is only one unique control in the Game, so it's not a matter of a layer, but rather that there is no MediaPlayer control in the ContentView.
You can try putting the Game and MediaPlayer in the same Layout and then displaying them together via SetContentView.
Update:
After testing, it is not a good idea to use stacked views to control video playback. This will lead to the following major problems.
- Placing Game and MediaPlayer in the same view will result in a larger memory footprint.
- It is difficult to achieve a smooth transition animation when selecting a video to play.
Therefore, it is a better choice to use a pop-up window to isolate the two views and then pop up the MediaPlayer through the play event in the Game.
The following is the core code to implement this function.
public class VideoDialog : Dialog
{
public VideoDialog(Context context) : base(context) {
initView();
}
private void initView()
{
SetContentView(Resource.Layout.VideoLayout);
// setting width and height
WindowManagerLayoutParams layoutParams = Window.Attributes;
layoutParams.Width = WindowManagerLayoutParams.MatchParent;
layoutParams.Height = WindowManagerLayoutParams.WrapContent;
Window.Attributes=layoutParams;
}
}
Show the dialog in event:
button.Click += (s, e) =>
{
VideoDialog customDialog = new VideoDialog(this);
customDialog.Show();
};
Best Regards,
Alec Liu.
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.