americosfacebook / googletv-issues

Automatically exported from code.google.com/p/googletv-issues
0 stars 0 forks source link

Allow access to video audio tracks and subtitle tracks in mediaplayer #109

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
lacking NDK, it would be great if in the meantime we could access the audio and 
subtitle/closed captioning tracks of video files (mkv, m2ts...)

Original issue reported on code.google.com by sebastie...@gmail.com on 3 Dec 2012 at 9:33

GoogleCodeExporter commented 8 years ago
FCC regulations went into effect on March 30, 2013 that require content 
originally broadcast on terrestrial TV to have closed-captioning available on 
internet streams of the same content:
http://cpcweb.com/blog/2012/10/what-the-new-fcc-captioning-regulations-mean-for-
tv-broadcasters/

As the Google TV platform currently does not offer any way to display subtitles 
/ closed captioning tracks then there is no simple way to meet this 
requirement.  This functionality needs to be added to the Google TV platform 
immediately to prevent fines from the FCC for my company's Google TV apps for 
local broadcast stations.

Original comment by car...@gmail.com on 1 Apr 2013 at 4:39

GoogleCodeExporter commented 8 years ago
Google TV does support Closed Captioning using the closed captioning API 
(documentation release pending). 

TL;DR;

You need two things in your app.
1. TtmlTimedTextView ----> mTimedTextView
2. GtvVideoView ----> mVideoView.setOnTimedTextListener(mTimedTextView);

Closed captioning GtvMediaPlayer example:

package com.example.closedcaptionexample;

import com.google.android.tv.media.GtvMediaPlayer;
import com.google.android.tv.media.GtvMediaPlayer.TrackInfo;
import com.google.android.tv.widget.GtvMediaController;
import com.google.android.tv.widget.GtvVideoView;
import com.google.android.tv.widget.TtmlTimedTextView;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

public class MainActivity extends Activity {

  private static final String MEDIA_URI = "http://streams.smooth.vertigo.com/elephantsdream/Elephants_Dream_1024-h264-st-aac.ism/Manifest";
  private TtmlTimedTextView mTimedTextView = null;
  private GtvVideoView mVideoView  = null;
  private GtvMediaPlayer mGtvMediaPlayer = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.rr);

    mVideoView  = (GtvVideoView) findViewById(R.id.video);
    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener () {
      @SuppressLint("NewApi")
      @Override
      public void onPrepared(MediaPlayer mp) {
        if (mp instanceof GtvMediaPlayer) {
          mGtvMediaPlayer = (GtvMediaPlayer) mp;
          mGtvMediaPlayer.setLooping(true);

          mVideoView.start();

          TrackInfo[] trackInfo = mVideoView.getTrackInfo();
          for(int index = 0;index < trackInfo.length; index++) {
            int trackType = trackInfo[index].getTrackType();
            if (TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT == trackType) {
              String lang = trackInfo[index].getLanguage();
              Log.d("TRACK INFO", "TRACK ["+index+"] uses Language " + lang);
            }
          }
        }
      }});

    GtvMediaController c = new GtvMediaController(this, false);
    mVideoView.setMediaController(c);

    mTimedTextView = new TtmlTimedTextView(this);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    rl.addView(mTimedTextView, layoutParams);

    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            setResult(RESULT_OK);
            finish();
        }
    });

    mVideoView.setOnTimedTextListener(mTimedTextView);
    mVideoView.setVideoURI(Uri.parse(MEDIA_URI));
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
  }

}

Original comment by kri...@google.com on 1 Apr 2013 at 5:01

GoogleCodeExporter commented 8 years ago
This is fantastic news!  Thank you for your quick response!

One thing I am confused about though are the imports that begin with:
import com.google.android.tv

I cannot resolve any of those imports.  Is there a library I need to include?  
I don't see any libs in the android-sdk\add-ons\addon-google_tv_addon-google-13 
directory so I'm not sure what to do.

Thanks again!

Original comment by car...@gmail.com on 1 Apr 2013 at 8:18

GoogleCodeExporter commented 8 years ago
Can you reach out to me directly to discuss updates on this.
krispy@google.com

Original comment by kri...@google.com on 1 Apr 2013 at 8:53