Can't get vitamio to show subtitle - android-videoview

I'm using vitamio lib to make a video player. However, I can not find a way out to show embed subtitle. I've searched thoroughly on the Internet but there is no sample code. Here is my code :
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.videoview);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mVideoView
.setVideoPath(path);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mediaController = new MediaController(this);
mVideoView.setMediaController(mediaController);
mVideoView.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer arg0) {
// TODO Auto-generated method stub
mVideoView.setSubShown(true);
mVideoView.setSubPath(Environment
.getExternalStorageDirectory().getPath()+"/pi.srt");
}
});
}

You can use Vitamio 4.0 preview version

Related

Elements disappear after pause and resume

Testing my libGDX app in RoboVM, I have encountered a major problem. When I pause my app (by actually going to the Home screen or sending app invites via Facebook) and then return to my app, classes of my games disappear. As if it does not store data properly on the resume() method. First i though it there was a problem of my AssetLoader, but after some debugging I found that the situation is worse. Actual instances of classes and shapes disappear. As if they never existed.
After googling the issue, I found that it might be related to IOSGraphics, but I have not managed to fix the problem.
My IOSLauncher looks something like this, I have erased the Facebook & Google AdMob specific code.
protected IOSApplication createApplication() {
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
config.useAccelerometer = true;
config.useCompass = true;
config.orientationPortrait = true;
config.orientationLandscape = false;
return new IOSApplication(new Game(this), config);
}
#Override
public boolean didFinishLaunching(UIApplication application,
UIApplicationLaunchOptions launchOptions) {
FBSDKApplicationDelegate.getSharedInstance().didFinishLaunching(application, launchOptions);
initialize();
return true;
}
public void initialize() {
//...
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
#Override
public void showAds(boolean show) {
//...
}
#Override
public void shareOnFacebook() {
//...
}
#Override
public void inviteFriends() {
//....
}
#Override
public boolean openURL(UIApplication application, NSURL url,
String sourceApplication, NSPropertyList annotation) {
super.openURL(application, url, sourceApplication, annotation);
return FBSDKApplicationDelegate.getSharedInstance().openURL(
application, url, sourceApplication, annotation);
}
#Override
public void didBecomeActive(UIApplication application) {
super.didBecomeActive(application);
FBSDKAppEvents.activateApp();
}
#Override
public void willResignActive(UIApplication application) {
super.willResignActive(application);
}
#Override
public void willTerminate(UIApplication application) {
super.willTerminate(application);
}
}
This sounds similar to a threading bug I once encountered. I fixed it by deferring resize and resume but I'm not sure if it will help in your case. Something like this:
private boolean needResize, needResume;
private void resize (int width, int height){
needResize = true;
}
private void deferredResize ();
if (!needResize) return;
needResize = false;
int width = Gdx.graphics.getWidth();
int height = Gdx.graphics.getHeight();
//move your resize code here
}
private void resume (){
needResume = true;
}
private void deferredResume (){
if (!needResume) return;
needResume = false;
//move your resume code here
}
public void render (){
deferredResize();
deferredResume();
//...
}
I suggest that you start looking for an alternative to RoboVM to avoid more issues in the future, as Robovm was acquired by Microsoft Xamarin (sad but true) and the framework is no longer maintained. License keys (with Libgdx) will continue to work until the 17th of April 2017, there will be no further updates to RoboVM, be it new features or bug fixes.
As far as I know, Libgdx will switch to Multi-OS engine as the default iOS backend for newly created libGDX projects in the next couple of weeks.
After a couple of days filled with headache I found the solution!
LifeCycle methods like pause & resume, hide & show are not always called When they are supposed to be called, therefore data is not stored properly. This issue can completely break your game.
This thing only occurred when testing my game on the iOS platform, mainly when I opened a 3rd party app, Facebook in this case. No such thing found on Android, though.
The only thing I changed on the iOS version was calling the mentioned methods manually to make sure it always pauses and resumes when it has to.

Using GoogleApiClient in Fragment Android

I tried to load a Google map into a fragment. I don't know what the three lines should be... (the three lines commented with "problem!").
Most examples are using "this" in the parenthesis. I understand this is a fragment, not an activity, so I used "getActivity()" instead. But if I changed all three lines to getActivity(), it didn't work either. Please help! Thanks in advance!
public class MapFragment extends Fragment implements OnMapReadyCallback,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,com.google.android.gms.location.LocationListener {
private static final String TAG = "***MapFragment***";
private final int PERMISSION_CODE = 1;
private GoogleApiClient myGoogleApiClient;
private GoogleMap myMap;
private Location curLocation;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_target, container, false);
// create api client
if (myGoogleApiClient == null) {
myGoogleApiClient = new GoogleApiClient.Builder(getActivity()) // problem!
.addConnectionCallbacks(this) // problem!
.addOnConnectionFailedListener(this) // problem!
.addApi(LocationServices.API)
.build();
}
Here need context, u can use getActivity()
new GoogleApiClient.Builder(getActivity()) // problem!
Below two methods need callback, so your fragment must implement ConnectionCallbacks, OnConnectionFailedListener listeners.
.addConnectionCallbacks(this) // problem!
.addOnConnectionFailedListener(this) // problem!
Explanation
.addConnectionCallbacks method needs ConnectionCallbacks
.addOnConnectionFailedListener method needs OnConnectionFailedListener
You already implemented them
public class MapFragment extends Fragment implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
com.google.android.gms.location.LocationListener {
...
}
So, 'this' here refers your MapFragment class. And when u pass 'this' in above methods, they uses their callbacks.

Libgdx android back button exit app

I'm using libgdx in my game and I want to catch android back button.
I want this scenario:
I have three screens: Screen1, Screen2 and Screen3. When I'm on Screen3 and I press back button on android I want to open Screen2 screen, but in my case all app exit (Closes all sceens 1,2 and 3). I'm using this code:
#Override
public void show() {
backButtonPressed = false;
Gdx.input.setCatchBackKey(true);
}
#Override
public void hide() {
Gdx.input.setCatchBackKey(false);
}
#Override
public void render(float deltaTime) {
if (Gdx.input.isKeyPressed(Keys.BACK) && !backButtonPressed){
ScreenTransition transition = ScreenTransitionFade.init(0.5f);// init(0.5f, ScreenTransitionSlice.UP_DOWN, 10, Interpolation.pow5Out);
game.setScreen(new Screen2(), transition);
backButtonPressed = true;
}
}
The same code in Screen3 and Screen2 (new Screen1() and new Screen2())
Thanks
See catchbackkey not working (libgdx) Android for the solution - the short version is that you should be hooking isKeyUp

My Libgdx game slow when integrated Admob

I am a new game developing with libgdx. I have a problem with Admob ads. When I call "adView.loadAd(adRequest);" my game is slowl, when I start game, FPS ~ 60 , when I call adView.loadAd(adRequest) my game is slowly FPS ~ 30.
Here is my
public class MainActivity extends AndroidApplication implements IActivityRequestHandler {
protected AdView adView;
AdRequest adRequest;
private final int SHOW_ADS = 1;
private final int HIDE_ADS = 0;
protected Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SHOW_ADS: {
System.out.println("SHOW ADVIEW");
adView.setVisibility(View.VISIBLE);
break;
}
case HIDE_ADS: {
adView.setVisibility(View.GONE);
break;
}
}
}
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
View gameView = initializeForView(new MyGdxGame(this), false);
// Create and setup the AdMob view`enter code here`
adView = new AdView(this, AdSize.BANNER, "XXXXXX"); // Put in your
// secret key
// here
adRequest = new AdRequest();
adView.loadAd(adRequest);
// adView.loadAd(new AdRequest());
// Add the libgdx view
layout.addView(gameView);
// Add the AdMob view
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
// Hook it all up
setContentView(layout);
}
// This is the callback that posts a message for the handler
#Override
public void showAds(boolean show) {
handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
}
}
I read topic Using interstitials from Admob in a Libgdx game for Android, it's slow when dismissing it
but not solution
Please help me if you have a solution.
This is a known issue and at the moment you cant change it.
Post at the libgdx Forum
It has nothing todo with your code. I think

load html at listview item onclick

I'm now stuck in html loading from my assets folder. I've several html pages under assets folder and have to load those at listview item onclick. Each listview item own their html pages.Does anybody know how i can get onclick event and how to show specific html pages ?
Thanks
public class WebViewWithListActivity extends Activity {
private String lv_arr[] = { "Android", "iPhone", "BlackBerry"};
ListView lv1;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv1 = (ListView) findViewById(R.id.listView1);
lv1.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, lv_arr));
lv1.setTextFilterEnabled(true);
lv1.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,long id)
{
AlertDialog.Builder adb = new AlertDialog.Builder(WebViewWithListActivity.this);
adb.setTitle("Selected item");
adb.setMessage("Selected Item is = "
+ lv1.getItemAtPosition(position));
adb.setPositiveButton("Ok", null);
Log.i("Selected item is ",(String) lv1.getItemAtPosition(position)+"" );
adb.show();
//TextView tvUrl = (TextView) view.findViewById(R.id.item2);
TextView tvUrl=(TextView) findViewById(R.id.item2);
if(lv1.getItemAtPosition(position).equals("Android"))
{
GlobalVariable.SetURL("http://www.google.co.in/");
Log.i("Global vari : ",GlobalVariable.GetURL());
Intent i = new Intent(WebViewWithListActivity.this,WebViewDemo.class);
//i.putExtra("http://www.google.co.in/", tvUrl.getText());
startActivity(i);
}
}
});
}
}
This is WebViewDemo. I simply extended Activity:
public class WebViewDemo extends Activity{
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_webview);
//String url =getIntent().getStringExtra("url");//get url that pass from the other screen
//Log.i("url ", url+"");
Log.i("Global vari : ",GlobalVariable.GetURL());
webView = (WebView)findViewById(R.id.wvDisplay);
WebSettings webSetting= webView.getSettings(); //create new settings for webView
webSetting.setJavaScriptEnabled(true); // enabled javascript
webView.setWebViewClient(new WebViewClient()); //set up webviewclient, this set not to open the default browser when link click
//Log.i("url ", url+"");
webView.loadUrl(GlobalVariable.GetURL());//load the web page
}
}
public class GlobalVariable extends Application{
private static String url;
public static String GetURL()
{
return url;
}
public static void SetURL(String URL) {
url = URL;
}
}
You can use ListView's setOnItemClickListener method to get click event on list items.
You can use WebView's loadUrl method to show your html pages. See WebView tutorial.
Dude ... give up ... it won't work -- no way to get this listener working when you have a webview inside a listview
You can use a custom webViewClient and catch links in the html, then you can do what ever you want will the clicks.