Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Martin Finkel
LibVLCSharp
Commits
52abb3c9
Commit
52abb3c9
authored
May 07, 2018
by
Martin Finkel
Browse files
VideoView is a View, not an activity
parent
0dac1158
Changes
5
Hide whitespace changes
Inline
Side-by-side
LibVLCSharp.Android.Sample/MainActivity.cs
View file @
52abb3c9
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
_surface
View
;
VideoView
_video
View
;
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
LibVLCSharp.Android.Sample/Resources/Resource.Designer.cs
View file @
52abb3c9
...
...
@@ -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
{
...
...
LibVLCSharp.Android.Sample/Resources/layout/Main.axml
View file @
52abb3c9
...
...
@@ -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
LibVLCSharp/Platforms/Android/VideoView.cs
View file @
52abb3c9
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
At
tach
SurfaceView
(
SurfaceView
surfaceView
)
public
void
De
tach
(
)
{
_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
LibVLCSharp/Shared/IVideoView.cs
View file @
52abb3c9
...
...
@@ -3,10 +3,9 @@
public
interface
IVideoView
{
MediaPlayer
MediaPlayer
{
get
;
}
Instance
Instance
{
get
;
}
void
Attach
View
(
object
surface
);
void
Detach
View
();
void
Attach
(
);
void
Detach
();
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment