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

VideoView is a View, not an activity

parent 0dac1158
using Android.App;
using Android.OS;
using Android.Views;
using LibVLCSharp.Platforms.Android;
using Android.Widget;
using LibVLCSharp.Shared;
using VideoView = LibVLCSharp.Platforms.Android.VideoView;
namespace LibVLCSharp.Android.Sample
{
[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)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
_surfaceView = FindViewById<SurfaceView>(Resource.Id.surfaceView);
AttachSurfaceView(_surfaceView);
SetContentView(Resource.Layout.Main);
}
protected override void 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
}
}
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
{
......
......@@ -3,11 +3,4 @@
android:orientation="vertical"
android:layout_width="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>
\ No newline at end of file
using Android.App;
using Android.OS;
using System;
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Views;
using LibVLCSharp.Shared;
using Org.Videolan.Libvlc;
namespace LibVLCSharp.Platforms.Android
{
[Activity(Label = "VideoView")]
public abstract class VideoView : Activity, IVLCVoutCallback
public class VideoView : SurfaceView, IVLCVoutCallback, IVideoView
{
MediaPlayer _mediaPlayer;
Instance _instance;
AWindow _awindow;
LayoutChangeListener _layoutListener;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
#region ctors
Core.Initialize();
public VideoView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) => Init();
_instance = new Instance();
_mediaPlayer = new MediaPlayer(_instance);
public VideoView(Context context) : base(context) => Init();
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.AddCallback(this);
_awindow.SetVideoView(this);
_awindow.AttachViews();
_mediaPlayer.SetAndroidContext(_awindow.Handle);
_layoutListener = new LayoutChangeListener(_awindow);
AddOnLayoutChangeListener(_layoutListener);
}
public void AttachSurfaceView(SurfaceView surfaceView)
public void Detach()
{
_awindow.SetVideoView(surfaceView);
_awindow.AttachViews();
surfaceView.AddOnLayoutChangeListener(new LayoutChangeListener(_awindow));
_awindow.RemoveCallback(this);
_awindow.DetachViews();
_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;
public Instance Instance => _instance;
void Init()
{
Core.Initialize();
_instance = new Instance();
_mediaPlayer = new MediaPlayer(_instance);
}
}
}
\ No newline at end of file
......@@ -3,10 +3,9 @@
public interface IVideoView
{
MediaPlayer MediaPlayer { get; }
Instance Instance { get; }
void AttachView(object surface);
void DetachView();
void Attach();
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