Fenster


Source link: https://github.com/malmstein/fenster

Fenster

A library to display videos in a TextureView using a custom MediaPlayer controller as described in this blog post http://www.malmstein.com/blog/2014/08/09/how-to-use-a-textureview-to-display-a-video-with-custom-media-player-controls/

Install

To get the current snapshot version:

buildscript {

  repositories {

jcenter()
  
}

  dependencies {

classpath 'com.malmstein:fenster:0.0.2'
  
}
 
}

minSDK

The minSDK for the use of the library is minSDK 16

Displaying a video with custom controller

Add a TextureVideoView and a PlayerController to your Activity or Fragment

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/default_bg"
tools:context=".DemoActivity">
 <com.malmstein.fenster.view.FensterVideoView
  android:id="@+id/play_video_texture"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:keepScreenOn="true"
  android:fitsSystemWindows="true" />
 <com.malmstein.fenster.controller.MediaFensterPlayerController
  android:id="@+id/play_video_controller"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:animateLayoutChanges="true"
  android:fitsSystemWindows="true" />  </FrameLayout>

Setting video URL

In order to display a video, simply set the video URL and call start. You can also start the video from a desired second too.

@Override protected void onPostCreate(Bundle savedInstanceState) {

  super.onPostCreate(savedInstanceState);

textureView = (TextureVideoView) findViewById(R.id.play_video_texture);

  playerController = (PlayerController) findViewById(R.id.play_video_controller);

textureView.setMediaController(playerController);

textureView.setVideo("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4",

  PlayerController.DEFAULT_VIDEO_START);

  textureView.start();
 
}

Exposed listeners

By default there are the exposed listeners. The NavigationListener will listen to the to Previous and Next events triggered by the controller. The VisibilityListener will be triggered when the PlayerController visibility changes.

playerController.setNavigationListener(this);
 playerController.setVisibilityListener(this);

Using the Gesture Detection Player Controller

Attach a listener to your player controller

As described in this blog post http://www.malmstein.com/how-to-use-a-textureview-to-display-a-video-with-custom-media-player-controls/ it's very simple to use. Just add a listener to Player Controller

playerController.setFensterEventsListener(this);

The Fenster Events Listener allows you to react to the gestures

public interface FensterEventsListener {

void onTap();

void onHorizontalScroll(MotionEvent event, float delta);

void onVerticalScroll(MotionEvent event, float delta);

void onSwipeRight();

void onSwipeLeft();

void onSwipeBottom();

void onSwipeTop();
 
}

Use MediaPlayerController instead of SimpleMediaPlayerController

MediaFensterPlayerController also shows volume and brightness controls, if you just want to use a simple media controller then the recommendation is to use SimpleMediaFensterPlayerController

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/default_bg"
tools:context=".DemoActivity">
 <com.malmstein.fenster.view.FensterVideoView
  android:id="@+id/play_video_texture"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:keepScreenOn="true"
  android:fitsSystemWindows="true" />
 <com.malmstein.fenster.controller.SimpleMediaFensterPlayerController
  android:id="@+id/play_video_controller"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_alignParentBottom="true"
  android:animateLayoutChanges="true"
  android:fitsSystemWindows="true" />  </FrameLayout>

Using the Volume and Brightness Seekbar

Add them to your layout:

  <com.malmstein.fenster.seekbar.BrightnessSeekBar
  android:id="@+id/media_controller_volume"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />
  <com.malmstein.fenster.seekbar.VolumeSeekBar
  android:id="@+id/media_controller_volume"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" />

Initialise them from your Fragment or Activity:

mVolume = (VolumeSeekBar) findViewById(R.id.media_controller_volume);
 mVolume.initialise(this);
  mBrightness = (BrightnessSeekBar) findViewById(R.id.media_controller_brightness);
 mBrightness.initialise(this);
 

You'll get a callback when the seekbar is being dragged:

@Override public void onVolumeStartedDragging() {

  mDragging = true; 
}
  @Override public void onVolumeFinishedDragging() {

  mDragging = false; 
}
  @Override public void onBrigthnessStartedDragging() {

  mDragging = true; 
}
  @Override public void onBrightnessFinishedDragging() {

  mDragging = false; 
}

Support for different video origins

The setVideo() method allows you to load remote or local video files. You can also set the start time of the video (useful if you want to resume content), passing in a integer which corresponds to Milliseconds.

Loading a remote stream

@Override protected void onPostCreate(Bundle savedInstanceState) {

  super.onPostCreate(savedInstanceState);

textureView = (TextureVideoView) findViewById(R.id.play_video_texture);

  playerController = (PlayerController) findViewById(R.id.play_video_controller);

textureView.setMediaController(playerController);

textureView.setVideo("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");

  textureView.start();
 
}

Loading a local stream

Fenster uses the AssetFileDescriptor in order to load a local video stream.

@Override protected void onPostCreate(Bundle savedInstanceState) {

  super.onPostCreate(savedInstanceState);

textureView = (TextureVideoView) findViewById(R.id.play_video_texture);

  playerController = (PlayerController) findViewById(R.id.play_video_controller);

textureView.setMediaController(playerController);

 AssetFileDescriptor assetFileDescriptor = getResources().openRawResourceFd(R.raw.big_buck_bunny);

  textureView.setVideo(assetFileDescriptor);

textureView.start();
 
}

Support for video scaling modes

Sets video scaling mode. To make the target video scaling mode effective during playback, the default video scaling mode is VIDEO_SCALING_MODE_SCALE_TO_FIT. Uses setVideoScalingMode

There are two different video scaling modes: scaleToFit and crop

In order to use it, Fenster allows you to pass in an argument from the xml layout:

<com.malmstein.fenster.view.FensterVideoView
android:id="@+id/play_video_texture"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:scaleType="crop" />

License

(c) Copyright 2016 David Gonzalez  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Modern API for SQLiteDatabase and ContentProvider.

Typed Preferences provides classes which allow to store and retrieve settings from the preferences. There is an individual class for each native type:

  • BooleanPreference
  • DoublePreference
  • FloatPreference
  • IntPreference
  • LongPreference
  • StringPreference

A python utility to pull android database files of a particular app from an emulator without having to go through all the regular adb shenanigans every time, features:

  • pulls the .db files from the databases folder to a local directory on your dev computer
  • supports multiple devices
  • supports selective db file pulls
  • tested on a Genymotion emulator

FFmpeg-Android-Java:

  • FFmpeg for Android compiled with x264, libass, fontconfig, freetype and fribidi
  • Supports Android L

Supported Architecture:

  • armv7
  • armv7-neon
  • x86

Shape Image View provides a set of custom shaped android imageview components, and a framework to define more shapes. Implements both shader and bitmap mask based image views.

Toast-like alert pattern for Android inspired by the Google Material Design Spec

Features:

  • Set message text and optionally duration
  • Shows only one message at a time
  • Can have action item (e.g. undo, refresh, etc.)
  • Swipe down to dismiss all notifications as per documentation
  • Backwards compatible to 2.3.x

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes