How to play a video

I would like to make an app that plays 20 videos. all the videos would be embedded in the app. I couldt even import a video in my ios project.

I have done this very easely with desktop app, but not with IOS app

tks for the help

  • Insert/CopyFile
  • Destination : Resources folder
  • Drag the file over (here my file is “spacetest.mp4”)
  • Drag the copyfile immediately after the gear, in iOS Build Settings
  • Drag an HTMLViewer to the view
  • In the Open event or anywhere needed :

Sub Open() Handles Open dim f as FolderItem = SpecialFolder.GetResource("spacetest.mp4") me.LoadURL(f.URLPath) End Sub

If you use iOSKit, there is an class in the Extensions Module for this called MPMoviePlayerController. There is a view which demonstrates how to use it in the example project called RecordPlayVideo. The example project doesn’t compile with the latest version of Xojo because handling of Tables was changed, but all of the example views will work independently if added to a separate project, or in an older version of Xojo.

Im sorry but im really new on this

for michel

how to you insert when i tried to go to file insert it refuse to insert any video files?

how do I get the ioskit, is there a good tutorial on using the iso kit for newbie? with xoyo

Im sorry but im need more details instructions

  • You click the menu Insert, and select Build Step, then Copy Files.
  • It creates a small CopyFiles1 object at the bottom of the project on the left.
  • Drag that to Build Settings iOS.
  • Open iOS, and drag CopyFiles1 under the gear
  • Double click CopyFiles1
  • Drag your video files into the center of the IDE
  • On the right of the IDE set Destination to Resources

All that simply replaces dragging the file into the project, because otherwise Xojo cannot be imported.

Then

  • Drag an HTMLViewer to the view

  • In the Open event or anywhere needed :

    dim f as FolderItem = SpecialFolder.GetResource("spacetest.mp4") HTMLViewer1.LoadURL(f.URLPath)

It should not be that different from what you did in Desktop…

BTW I have filed a feature request asking that it be possible to drag video files directly into the project. It is currently in beta, but I requested it to be made public.

<https://xojo.com/issue/45038>

[quote=287542:@serge ramelli]how do I get the ioskit, is there a good tutorial on using the iso kit for newbie? with xoyo

Im sorry but im need more details instructions[/quote]
You can find the repository here:
https://github.com/kingj5/iOSKit

Download the project and open it in Xojo. If you open it in 2016r2 or earlier (not the most recent version) then everything will run in an example project to show you how to use the core features. The classes themselves work in the most recent version, just not the demo views because of changes to table handling. You need to copy the Modules folder from inside the project into your own project to use the classes. The example view which shows you how to use the MPMoviePlayerClass is located in the Example Views folder and is called RecordPlayVideo. You can directly copy that into your project if you like. That should provide you a solid start.

Hello Michel,

Tks I got the top point of the open event, Im confised because when I double click on my htmlViewer I have no event to choose, same if I drag a button and I double click the open event window is empty. Sorry for bothering you with such newbie questions!

tks for you help in any case

[quote=287577:@serge ramelli]Hello Michel,

Tks I got the top point of the open event, Im confised because when I double click on my htmlViewer I have no event to choose, same if I drag a button and I double click the open event window is empty. Sorry for bothering you with such newbie questions!

tks for you help in any case[/quote]

Serge, I thought you talked about an iOS project.

Now I am the one confused. Double click (double tap) is unusual in iOS, and there is no event for it in HTMLViewer. Why do you need it ?

I see you are indeed quite new at that. Here is a sample project. Maybe that will help you understand :
Video-Project.zip

Maybe you are trying to click on things in the iosScreen rather than the iosView. You need to make sure you are in the view section.

Here’s a short video using @Michel Bujardet code to get the video to play in iOS.

Video Link: https://youtu.be/yW3eAxAq0T4

Hello MIchel,

yes that works

I have a questions could I hire to make a template app, I have allready all the desing the destop version. Its a very simple app where you have a list of thumnail when you click on a thumnail it plays a video

Im going to take forever to create it, an I contact you for this?

And this is where Michel’s solution is no longer as easy to work with since you can’t leverage the internal power of the Apple frameworks to get thumbnails. I recommend that you seriously look into using iOSKit to accomplish this using native code. It allows you to grab thumbnails with relative ease and play movies using a native player instead of a less conventional and nonstandard htmlviewer. A quick example project can be found below. Although Michel’s solution will work for a quick and dirty hack, it won’t shine when you get to more complicated and involved projects.

https://www.dropbox.com/s/l1q4e64ijf8b9l5/MovieExample.xojo_binary_project?dl=1

I included a function to get a thumbnail of a movie.

Hello Jason,
thanks for the Thumbnail function, it works perfectly! The only problem I have is getting the right image orientation. I think the solution would be to set true the appliesPreferredTrackTransform boolean property, but I don’t know how to do this. Could you help me please?

tks a lot!

Updated method: the new lines to set the property are in the middle

[code] dim url as new Foundation.NSURL(videoFile)

declare function initWithURL_ lib AVFoundationLib selector “initWithURL:options:” (obj_id as ptr, url as ptr, options as ptr) as ptr
declare function alloc lib FoundationLib selector “alloc” (clsref as ptr) as Ptr
dim asset as Ptr = initWithURL_(alloc(NSClassFromString(“AVURLAsset”)), url, nil)

declare function initWithAsset_ lib AVFoundationLib selector “initWithAsset:” (obj_id as ptr, asset as ptr) as Ptr
dim generator as ptr = initWithAsset_(alloc(NSClassFromString(“AVAssetImageGenerator”)), asset)

////////// This part is new //////////
declare sub setAppliesPreferredTrackTransform_ lib AVFoundationLib selector “setAppliesPreferredTrackTransform:” (obj_id as ptr, yesNo as Boolean)
setAppliesPreferredTrackTransform_(generator,True)
////////// End of new Part //////////

dim err as ptr

declare function CMTimeMake lib “CoreMedia” (value as Int64, timescale as int32) as CMTime
dim time as CMTime = CMTimeMake(1,1)

declare function copyImage_ lib AVFoundationLib selector “copyCGImageAtTime:actualTime:error:” (obj_id as ptr, time as CMTime, actualTime as ptr, err as ptr) as ptr

dim cgimgRef as ptr = copyImage_(generator, time, nil, err)

declare function initWithCGImage_ lib UIKitLib selector “initWithCGImage:” (obj_id as ptr, img as ptr) as ptr
dim uiimage as ptr = initWithCGImage_(alloc(NSClassFromString(“UIImage”)), cgimgRef)

Return iOSImage.FromHandle(uiimage)[/code]

You may also need to scale the image to new (smaller) dimensions. There is a scale image method for this included in the extensions Module of iOSKit as well.

Grazie mille Jason!

Using the info I found in this thread I get a video to play in the Simulator just fine. But build and run on iPad and when the code tries to play video the app immediately crashes.
When I select view package contents of the built app to my surprise there is no Contents folder, just a lot of items including the video file. There is no Resources folder. The copy files behaviour specified Destination as Resources Folder.
I am assuming that iOS app bundles are different than MacOS app bundles. Or do I have a problem?

For the sake of debugging, let’s assume the IDE built the .ipa correctly. What is your code to acquire the folder item of the video?

When a thread is almost four years old, it is okay to start your own too! :wink:

Should have done some more debugging before posting. The code to get the video file is working. The code that doesn’t work is:

player = new Extensions.MPMoviePlayerController(mediaURL)

player is a property of type Extensions.MPMoviePlayerController based on a class in iOSKit. Works in simulator.

You might want to start a new thread for yourself. Xojo, Inc. is not officially able to help with iOSKit, you’ll need the author of or someone familiar with that library. I am not, and was just trying to help you work out basic debugging :frowning: Best luck!