0

I´m using Delphi XE5 for an app that creates an .avi video file for the user. After successfully creating it (or even just because the user wants to watch the video again) it tries to open it using the app of choice for videos. I understand that android picks the right app for the file type or you can direct it providing the MIME type of the file. So, using intents from Delphi I´m doing

intent:=TJIntent.Create;
intent.setAction(TJIntent.JavaClass.ACTION_VIEW);      
intent.setData(TJnet_Uri.JavaClass.parse(StringToJString('file://'videoFile)));
intent.setType(StringToJString('video/avi'));

When I do this, a very basic video player appears (the Running Apps section of Setting show an app called Android Media running) with a play button but does not show the video. But if you use any File Manager or even go through the Gallery and click on the file it plays nicely using the View Video app.

I can´t make my app call View Video directly, not even show a list of video apps for the user to choose it. I tried different MIME types like

intent.setType(StringToJString('video/*'));

and even

intent.setType(StringToJString('*/*'));

Which lets the user choose from any app in its device (nosense but just for testing) so he can choose View Video but even doing that the app shows only a play button and displays no content when pressed.

So, it looks like when called from my app, View Video can´t play the video I created (I do not have it opened or something like that, checked) but when called from other apps it can.

Does anybody know of bugs or limitations when using intents from Delphi XE5 or maybe I´m not doing it right?

Kromster
  • 7,181
  • 7
  • 63
  • 111
  • If I would be on your place I would check the string you pass as file location to setData. Now I don't have direct expirience with making application for android but based on the fact that application opens but there is no content in it I would suspect that wrong (invalid) file location is passed to it. Or perhaps it is the wrong order of your intent calls. Wouldn't it be better to set file location and file type before setting Action. If setting action is what launches the aplication it is no wonder that there is no content in it since at that time it still isn't provided to intent object. – SilverWarior Jan 29 '15 at 16:27
  • SilverWarrior your comment led me in the right way! Checking the Data property I discovered that SetType was totally ruining its content! I gues it´s a nasty XE5 bug. I was able to use another setter that works well and it worked : both data and type were correctly set and after choosing a video app the video is played ok. As for the last suggestion its not that Setaction fires the intent, there is an explicit StartActivity method that I didnt include. But after all checking the data content was the obvious thing to do and I was not seeing it until you told me too. Many thanks! – Diego Anfossi Jan 30 '15 at 20:31
  • I'm glad I could help. Unfortunately I don't own any android device to be able to test if that bug was solved in newer versions of Delphi. But I think it woul not be bad if you can go and check the embarcadero quality center if someone had alread posted isue about this bug and then post if if nobody else did. The worse thing that can happen is that you gat an answer "This was laready fixed in X version". – SilverWarior Jan 31 '15 at 08:46

1 Answers1

0

intent.settype in Delphi XE5 was ruining the contents of the data property. Using another setter like SetDataAndType works well. Use that one! Not sure if they fixed it in XE6 or XE7.

Kromster
  • 7,181
  • 7
  • 63
  • 111