Android SDK Extras

You must use the Uplynk player AAR file instead of the JAR file to use the features described in this article. The AAR file contains the JAR file in addition to some required Android resources.

To use the AAR file

  1. Edit android/app/build.gradle and add the AAR dependency.

    android/app/build.gradle:

    dependencies {
    	...
    	compile(name: 'upLynkLib-release', ext: 'aar')
    }
  2. Edit android/build.gradle and add the "flatDir" directive to the "allprojects" section, where "libs" is the location of the AAR file.

    android/build.gradle:

    	allprojects {
    		repositories {
    			...
    			flatDir {
    				dirs 'libs'
    			}
    		}
    	}

MediaController

Android’s stock MediaController is a set of on-screen controls for video playback. It provides Play/Pause, Fast-Forward, Rewind, Previous, and Next buttons, as well as a seek bar with playback time info.

Uplynk’s MediaController builds on the stock MediaController by adding functionality like:

It is available in the Uplynk Player Library build 96 and later.

To use the MediaController

  1. Change import from:

    android.widgets.MediaController

    to:

    com.uplynk.media.widgets.MediaController
  2. Implement additions to the MediaController.MediaPlayerControl interface:

    MediaController.MediaPlayerControl additions (build 96):

    /**
     * Gets a list of audio tracks
     * @return vector of UplynkTrackInfo objects
     */
    Vector<MediaPlayer.UplynkTrackInfo> getAudioTracks();
    
    /**
     * Select an audio track
     * @param trackNum 0-based index
     */
    void selectAudioTrack(int trackNum);
    
    /**
     * Gets a list of subtitle tracks
     * @return vector of UplynkTrackInfo objects
     */
    Vector<MediaPlayer.UplynkTrackInfo> getSubtitleTracks();
    
    /**
     * Select a subtitle track
     * @param trackNum 0-based index
     */
    void selectSubtitleTrack(int trackNum);
    
    /**
     * Turn caption display on or off
     * @param enabled True to display captions, false to hide
     */
    void setCaptionsEnabled(boolean enabled);
    
    /**
     * Sets the display style for captions
     * @param style com.uplynk.media.CaptionStyle object
     */
    void setCaptionStyle(CaptionStyle style);
    
    /**
     * Sets the volume
     * @param volume Value range 0.0 to 1.0
     */
    void setVolume(float volume);
    
    /**
     * Read if the currently playing media is a live stream (vs. VOD)
     *
     * @return true if live, false if VOD
     */
    boolean isLive();
    
    /**
     * Get the segment map, which comes from the MediaPlayer's
     * onUplynkSegmentList(MediaPlayer mp, Vector<MediaPlayer.UplynkSegment> segments) call-back
     */
    Vector<MediaPlayer.UplynkSegment> getSegmentMap();

    Most of these interface functions can be simple pass-through functions to call the corresponding functions in the MediaPlayer class.

    Example:

    public Vector < MediaPlayer.UplynkTrackInfo > getAudioTracks() {
    	if (_mediaPlayer != null) {
    		return _mediaPlayer.getAudioTrackOptions();
    	}
    	return null;
    }
  3. Update call to setAnchorView():

    From setAnchorView(View):

    _mediaController.setAnchorView((View) _surfaceView.getParent());
    

    To setAnchorView(FrameLayout):

    _mediaController.setAnchorView((FrameLayout) _surfaceView.getParent());

Additional Features and Customizations

Dialog Styles

Two types of dialogs can be shown: the FULL_DIALOG type will show a CaptionSettings or AudioSettings dialog, or TRACK_SELECTION_ONLY will show the TrackSelector dialog. (The dialogs can also be used separately from the MediaController)

Set Dialog Type (build 96):

/**
 * Changes the type of dialog shown for the CC and Audio dialogs
 *
 * @param subtitleDialogType FULL_DIALOG, or TRACK_SELECTION_ONLY
 * @param audioDialogType    FULL_DIALOG, or TRACK_SELECTION_ONLY
 */
public void setDialogType(DialogTypes subtitleDialogType, DialogTypes audioDialogType)

Caption Styles

Caption style settings in the CC dialog can be initialized and applied to the MediaPlayer. Must be called after setMediaPlayer() has been called.

Initialize Captions (build 96):

/**
 * Initialize captions to the style given. The captionStyle could be stored in the app and
 * restored on startup. Must be called after setMediaPlayer() has been called.
 * @param captionStyle the caption style
 * @param channelNum   the subtitle track number to default to
 */
public void initializeCaptions(boolean captionsEnabled, CaptionStyle captionStyle, int channelNum)

Title Text Fields

The three ‘Title’ text fields can be set or hidden using NULL. Hidden by default.

Title Text Fields (build 96):

/**
 * Set the 'Title' text fields at the top of the screen
 *
 * @param largeText  text to display or null to hide
 * @param mediumText text to display or null to hide
 * @param smallText  text to display or null to hide
 */
public void setTitleText(String largeText, String mediumText, String smallText)

References

Android MediaController (android.widget.MediaController)

AudioSettings Dialog

The AudioSettings class displays a dialog allowing the user to select an audio track and to set the playback volume. Also handles the selections and interacts with the MediaPlayer via MediaPlayerControl.

AudioSettings (build 96):

/**
 * Constructor
 *
 * @param context       The activity's context
 * @param playerControl interface class using com.uplynk.widgets.MediaController.MediaPlayerControl
 */
public AudioSettings(Context context, com.uplynk.widgets.MediaController.MediaPlayerControl playerControl)

/**
 * Shows the dialog. Changes are applied immediately upon selection.
 */
public void showDialog()

CaptionSettings Dialog

The CaptionSettings class displays a dialog allowing the user to select font and background styles for displaying subtitles. Also handles the selections and interacts with the MediaPlayer via MediaPlayerControl.

CaptionSettings (build 96):

 /**
 * Constructor
 *
 * @param context       The activity's context
 * @param playerControl interface class using com.uplynk.widgets.MediaController.MediaPlayerControl
 */
public CaptionSettings(Context context, com.uplynk.widgets.MediaController.MediaPlayerControl playerControl)

 /**
 * Displays the dialog for choosing caption settings. On 'Apply', the settings are set using
 * the MediaController interface. On 'Cancel' or other dismissal, no changes are applied.
 */
public void showDialog()

TrackSelector Dialog

Shows a dialog for audio or subtitle tracks, and then handles the user input.

TrackSelector (build 96):

/**
 * Constructor
 * @param context       The activity's context
 * @param playerControl interface class using com.uplynk.widgets.MediaController.MediaPlayerControl
 */
public TrackSelector(Context context, MediaController.MediaPlayerControl playerControl)

/**
 * Displays the track selection dialog. Dialog is dismissed upon selection and the selection
 * is applied to the MediaPlayer
 * @param selectionType The type of track to select: AUDIO or SUBTITLES
 */
public void showTrackOptions(TrackSelectionType selectionType)

UplynkTrackAdapter ArrayAdapter

An ArrayAdapter for the MediaPlayer.UplynkTrackInfo class

UplynkTrackAdapter extends ArrayAdapter<MediaPlayer.UplynkTrackInfo> (build 96):

public UplynkTrackAdapter(Context context, int textViewResourceId, List<MediaPlayer.UplynkTrackInfo> objects)

@Override
public int getCount()

@Override
public MediaPlayer.UplynkTrackInfo getItem(int position)

@Override
public long getItemId(int position)

@Override
public View getView(int position, View convertView, ViewGroup parent)

SeekBarSegmentedTrack Drawable

A Drawable class that can be used in place of SeekBar's default seek track via Seekbar.setProgressDrawable(Drawable d). It displays content and ad segments in the colors specified by CONTENT_COLOR and AD_COLOR fields. The segment map is updated by calling setSegmentMap(...).

SeekBarSegmentedTrack extends Drawable (build 96):

public static int AD_COLOR;
public static int CONTENT_COLOR;

/**
 * Constructor
 */
public SeekBarSegmentedTrack()

/**
 * Set the segment map data to be used for drawing the track
 * @param segmentMap Vector of UplynkSegment's
 */
public void setSegmentMap(Vector<MediaPlayer.UplynkSegment> segmentMap)