Commit 52abb3c9 authored by Martin Finkel's avatar Martin Finkel

VideoView is a View, not an activity

parent 0dac1158
using Android.App; using Android.App;
using Android.OS; using Android.OS;
using Android.Views; using Android.Views;
using LibVLCSharp.Platforms.Android; using Android.Widget;
using LibVLCSharp.Shared; using LibVLCSharp.Shared;
using VideoView = LibVLCSharp.Platforms.Android.VideoView;
namespace LibVLCSharp.Android.Sample namespace LibVLCSharp.Android.Sample
{ {
[Activity(Label = "LibVLCSharp.Android.Sample", MainLauncher = true)] [Activity(Label = "LibVLCSharp.Android.Sample", MainLauncher = true)]
public class MainActivity : VideoView public class MainActivity : Activity
{ {
SurfaceView _surfaceView; VideoView _videoView;
protected override void OnCreate(Bundle savedInstanceState) protected override void OnCreate(Bundle savedInstanceState)
{ {
base.OnCreate(savedInstanceState); base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource // Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main); SetContentView(Resource.Layout.Main);
_surfaceView = FindViewById<SurfaceView>(Resource.Id.surfaceView);
AttachSurfaceView(_surfaceView);
} }
protected override void OnResume() protected override void OnResume()
{ {
base.OnResume(); base.OnResume();
MediaPlayer.Play(new Media(Instance, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation)); _videoView = new VideoView(this);
AddContentView(_videoView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent));
_videoView.Attach();
_videoView.MediaPlayer.Play(new Media(_videoView.Instance, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4", Media.FromType.FromLocation));
}
protected override void OnPause()
{
base.OnPause();
_videoView.MediaPlayer.Stop();
_videoView.Detach();
_videoView.Dispose();
} }
} }
} }
\ No newline at end of file
...@@ -41,22 +41,6 @@ namespace LibVLCSharp.Android.Sample ...@@ -41,22 +41,6 @@ namespace LibVLCSharp.Android.Sample
} }
} }
public partial class Id
{
// aapt resource value: 0x7f040000
public const int surfaceView = 2130968576;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout public partial class Layout
{ {
......
...@@ -3,11 +3,4 @@ ...@@ -3,11 +3,4 @@
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<SurfaceView android:id="@+id/surfaceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
</SurfaceView>
</LinearLayout> </LinearLayout>
\ No newline at end of file
using Android.App; using System;
using Android.OS;
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Views; using Android.Views;
using LibVLCSharp.Shared; using LibVLCSharp.Shared;
using Org.Videolan.Libvlc; using Org.Videolan.Libvlc;
namespace LibVLCSharp.Platforms.Android namespace LibVLCSharp.Platforms.Android
{ {
[Activity(Label = "VideoView")] public class VideoView : SurfaceView, IVLCVoutCallback, IVideoView
public abstract class VideoView : Activity, IVLCVoutCallback
{ {
MediaPlayer _mediaPlayer; MediaPlayer _mediaPlayer;
Instance _instance; Instance _instance;
AWindow _awindow; AWindow _awindow;
LayoutChangeListener _layoutListener;
protected override void OnCreate(Bundle savedInstanceState) #region ctors
{
base.OnCreate(savedInstanceState);
Core.Initialize(); public VideoView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) => Init();
_instance = new Instance(); public VideoView(Context context) : base(context) => Init();
_mediaPlayer = new MediaPlayer(_instance);
public VideoView(Context context, IAttributeSet attrs) : base(context, attrs) => Init();
public VideoView(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) => Init();
public VideoView(Context context, IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) => Init();
#endregion
public MediaPlayer MediaPlayer => _mediaPlayer;
public Instance Instance => _instance;
public void Attach()
{
_awindow = new AWindow(new SurfaceCallback(_mediaPlayer)); _awindow = new AWindow(new SurfaceCallback(_mediaPlayer));
_awindow.AddCallback(this); _awindow.AddCallback(this);
_awindow.SetVideoView(this);
_awindow.AttachViews();
_mediaPlayer.SetAndroidContext(_awindow.Handle); _mediaPlayer.SetAndroidContext(_awindow.Handle);
_layoutListener = new LayoutChangeListener(_awindow);
AddOnLayoutChangeListener(_layoutListener);
} }
public void AttachSurfaceView(SurfaceView surfaceView) public void Detach()
{ {
_awindow.SetVideoView(surfaceView); _awindow.RemoveCallback(this);
_awindow.AttachViews(); _awindow.DetachViews();
surfaceView.AddOnLayoutChangeListener(new LayoutChangeListener(_awindow));
_mediaPlayer.SetAndroidContext(IntPtr.Zero);
RemoveOnLayoutChangeListener(_layoutListener);
_layoutListener.Dispose();
_layoutListener = null;
_awindow.Dispose();
_awindow = null;
} }
public virtual void OnSurfacesCreated(IVLCVout p0) public virtual void OnSurfacesCreated(IVLCVout vout)
{ {
} }
public virtual void OnSurfacesDestroyed(IVLCVout p0) public virtual void OnSurfacesDestroyed(IVLCVout vout)
{ {
} }
public MediaPlayer MediaPlayer => _mediaPlayer; void Init()
public Instance Instance => _instance; {
Core.Initialize();
_instance = new Instance();
_mediaPlayer = new MediaPlayer(_instance);
}
} }
} }
\ No newline at end of file
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
public interface IVideoView public interface IVideoView
{ {
MediaPlayer MediaPlayer { get; } MediaPlayer MediaPlayer { get; }
Instance Instance { get; } Instance Instance { get; }
void AttachView(object surface); void Attach();
void DetachView(); void Detach();
} }
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment