Android Open Source - android-player-samples Google Cast Sample Fragment






From Project

Back to project page android-player-samples.

License

The source code is released under:

Apache License

If you think the Android project android-player-samples listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.brightcove.player.samples.cast.basic;
/*from   w w  w.j  a  v a 2s.  c  o m*/
import android.os.Bundle;
import android.content.res.Resources;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import com.brightcove.cast.GoogleCastComponent;
import com.brightcove.cast.GoogleCastEventType;
import com.brightcove.player.event.EventEmitter;
import com.brightcove.player.view.BrightcovePlayerFragment;
import com.brightcove.player.view.BrightcoveVideoView;
import com.google.sample.castcompanionlibrary.widgets.MiniController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by bhnath on 3/10/14.
 */
public class GoogleCastSampleFragment extends BrightcovePlayerFragment {
    public static final String TAG = GoogleCastSampleFragment.class.getSimpleName();

    private GoogleCastComponent googleCastComponent;
    private MiniController miniController;
    private EventEmitter eventEmitter;

    public GoogleCastSampleFragment() {
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Perform the internal wiring to be able to make use of the BrightcovePlayerFragment.
        View view = inflater.inflate(R.layout.basic_cast_fragment, container, false);
        brightcoveVideoView = (BrightcoveVideoView) view.findViewById(R.id.brightcove_video_view);
        eventEmitter = brightcoveVideoView.getEventEmitter();
        super.onCreateView(inflater, container, savedInstanceState);

        // Initialize the android_cast_plugin which requires the application id of your Cast
        // receiver application.
        String applicationId = getResources().getString(R.string.application_id);
        googleCastComponent = new GoogleCastComponent(eventEmitter, applicationId, getActivity());

        // Initialize the MiniController widget which will allow control of remote media playback.
        miniController = (MiniController) view.findViewById(R.id.miniController1);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(GoogleCastComponent.CAST_MINICONTROLLER, miniController);
        eventEmitter.emit(GoogleCastEventType.SET_MINI_CONTROLLER, properties);

        // Send the location of the media (url) and its metadata information for remote playback.
        Resources resources = getResources();
        String title = resources.getString(R.string.media_title);
        String studio = resources.getString(R.string.media_studio);
        String url = resources.getString(R.string.media_url);
        String thumbnailUrl = resources.getString(R.string.media_thumbnail);
        String imageUrl = resources.getString(R.string.media_image);
        eventEmitter.emit(GoogleCastEventType.SET_MEDIA_METADATA,
                buildMetadataProperties("subTitle", title, studio, thumbnailUrl, imageUrl, url));

        brightcoveVideoView.setVideoPath(url);

        return view;
    }

    private Map<String, Object> buildMetadataProperties(String subTitle, String title, String studio,
                                                        String imageUrl, String bigImageUrl, String url) {
        Log.v(TAG, "buildMetadataProperties: subTitle " + subTitle + ", title: " + title
                + ", studio: " + studio + ", imageUrl: " + imageUrl + ", bigImageUrl: " + bigImageUrl
                + ", url: " + url);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(GoogleCastComponent.CAST_MEDIA_METADATA_SUBTITLE, subTitle);
        properties.put(GoogleCastComponent.CAST_MEDIA_METADATA_TITLE, title);
        properties.put(GoogleCastComponent.CAST_MEDIA_METADATA_STUDIO, studio);
        properties.put(GoogleCastComponent.CAST_MEDIA_METADATA_IMAGE_URL, imageUrl);
        properties.put(GoogleCastComponent.CAST_MEDIA_METADATA_BIG_IMAGE_URL, bigImageUrl);
        properties.put(GoogleCastComponent.CAST_MEDIA_METADATA_URL, url);
        return properties;
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        Log.v(TAG, "onCreateOptionsMenu");
        inflater.inflate(R.menu.main, menu);
        super.onCreateOptionsMenu(menu, inflater);

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(GoogleCastComponent.CAST_MENU, menu);
        properties.put(GoogleCastComponent.CAST_MENU_RESOURCE_ID, R.id.media_router_menu_item);
        eventEmitter.emit(GoogleCastEventType.SET_CAST_BUTTON, properties);
    }
}




Java Source Code List

com.brightcove.player.samples.adobepass.webview.basic.MainActivity.java
com.brightcove.player.samples.adobepass.webview.basic.WebViewActivity.java
com.brightcove.player.samples.ais.webview.basic.ChooserResponse.java
com.brightcove.player.samples.ais.webview.basic.MainActivity.java
com.brightcove.player.samples.ais.webview.basic.ResourceAccessResponse.java
com.brightcove.player.samples.ais.webview.basic.WebViewActivity.java
com.brightcove.player.samples.captioning.dfxp.MainActivityTest.java
com.brightcove.player.samples.cast.basic.GoogleCastSampleFragment.java
com.brightcove.player.samples.cast.basic.MainActivity.java
com.brightcove.player.samples.freewheel.basic.MainActivity.java
com.brightcove.player.samples.freewheel.hls.MainActivity.java
com.brightcove.player.samples.freewheelwidevine.basic.MainActivity.java
com.brightcove.player.samples.hls.basic.MainActivity.java
com.brightcove.player.samples.hls.id3.MainActivity.java
com.brightcove.player.samples.ima.adrules.MainActivity.java
com.brightcove.player.samples.ima.basic.MainActivity.java
com.brightcove.player.samples.ima.hls.MainActivity.java
com.brightcove.player.samples.imawidevine.adrules.MainActivity.java
com.brightcove.player.samples.imawidevine.basic.MainActivity.java
com.brightcove.player.samples.omniture.basic.MainActivity.java
com.brightcove.player.samples.onceux.basic.MainActivity.java
com.brightcove.player.samples.texture.basic.MainActivity.java
com.brightcove.player.samples.webvtt.MainActivity.java
com.brightcove.player.samples.widevine.basic.MainActivity.java
com.brightcove.samples.android.bundledvideo.basic.MainActivity.java
com.brightcove.samples.android.closedcaptioning.dfxp.MainActivity.java