I'm trying to make an Android ANE based on the YouTube API.
The YouTube API requires to start a new activity which when called through the ANE, disables the Air app activity until the user hits the back button.
What options do I have to run the YouTube activity in the background so that the Air app will stay interactive?
Activity Class:
/**
* A sample showing how to use the ActionBar as an overlay when the video is playing in fullscreen.
*
* The ActionBar is the only view allowed to overlay the player, so it is a useful place to put
* custom application controls when the video is in fullscreen. The ActionBar can not change back
* and forth between normal mode and overlay mode, so to make sure our application's content
* is not covered by the ActionBar we want to pad our root view when we are not in fullscreen.
*/
@TargetApi(11)
public class ActionBarDemoActivity extends YouTubeFailureRecoveryActivity implements
YouTubePlayer.OnFullscreenListener {
static public String vidToShow = null;
private ActionBarPaddedFrameLayout viewContainer;
private YouTubePlayerFragment playerFragment;
static public ActionBarDemoActivity inst;
private YouTubePlayer _player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inst = this;
setContentView(R.layout.action_bar_demo);
viewContainer = (ActionBarPaddedFrameLayout) findViewById(R.id.view_container);
playerFragment =
(YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
playerFragment.initialize(DeveloperKey.DEVELOPER_KEY, this);
//viewContainer.setActionBar(getActionBar());
// Action bar background is transparent by default.
//getActionBar().setBackgroundDrawable(new ColorDrawable(0xAA000000));
//ViewGroup.LayoutParams viewParams = rootView.getLayoutParams();
/* viewParams.width = 640;
viewParams.height = 360;*/
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CUSTOM_LAYOUT);
player.setOnFullscreenListener(this);
_player = player;
if (!wasRestored) {
player.cueVideo(vidToShow);
}
}
@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return (YouTubePlayerFragment) getFragmentManager().findFragmentById(R.id.player_fragment);
}
@Override
public void onFullscreen(boolean fullscreen) {
viewContainer.setEnablePadding(!fullscreen);
ViewGroup.LayoutParams playerParams = playerFragment.getView().getLayoutParams();
if (fullscreen) {
playerParams.width = MATCH_PARENT;
playerParams.height = MATCH_PARENT;
} else {
playerParams.width = WRAP_CONTENT;
playerParams.height = WRAP_CONTENT;
}
}
/**
*
* external methods
*
*/
static public void cueVideo(String id){
inst._player.cueVideo(id);
}
/**
* This is a FrameLayout which adds top-padding equal to the height of the ActionBar unless
* disabled by {@link #setEnablePadding(boolean)}.
*/
public static final class ActionBarPaddedFrameLayout extends FrameLayout {
private ActionBar actionBar;
private boolean paddingEnabled;
public ActionBarPaddedFrameLayout(Context context) {
this(context, null);
}
public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ActionBarPaddedFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
paddingEnabled = true;
}
public void setActionBar(ActionBar actionBar) {
this.actionBar = actionBar;
requestLayout();
}
public void setEnablePadding(boolean enable) {
paddingEnabled = enable;
requestLayout();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
/* int topPadding =
paddingEnabled && actionBar != null && actionBar.isShowing() ? actionBar.getHeight() : 0;
setPadding(0, topPadding, 0, 0);*/
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
}