Forum Archive

Video

robertiii

I am desperately trying to get a video from the camera roll and play it. I don't know how to use objc_util well enough though I've coded in xcode. Any help?

JonB

can you ou be a little more specific on your end goal? are you trying to integrate into a uiview? or just want to preview a video?

for instance, i have code in my objc_hacks repo that plays a video frame by frame, but no audio, etc.
There has been forum code that saves an asset to a local mp4 or mov, then you can play that in a webview, or in the quicklook.

JonB

also -- if you do the legwork and find an example of doing this in objc, it is usually pretty straightforward to convert to pythonista.

robertiii

Ok. So I want to present a video in a UI view. I'll look around to see what I can find. This part I am pretty clueless on

robertiii

The goal is to have video play one place with controls another so the video would be similar to a background

JonB

https://gist.github.com/3e708b73a04e5fc2e04569d9556198e3

Okay, this was not too bad. There is a lot of code defining CMTime and seeking ability, which is not needed if you just want to play without seeking.

robertiii

Thanks so much! I'll try it when I get a chance! Let you know how it works out

robertiii

Video works great!!!!!! Any idea on how to get the name of the selected video?

JonB

the phasset (in pick_asset) has a filename() method that returns the filename. You might want to modify that method as

return asseturl, str(phasset.filename() )
robertiii

Thanks so much! You are incredible!

robertiii

How would I go about removing this avplayer later.

robertiii

Also, how would I use a button to go back to the beginning of the video?

JonB

You can just remove_subview on the wrapper view to remove it. Technically maybe if you are planning on opening and closing a bunch of these, there is probably some cleanup that is required.

To seek. just use the seek function, and wrap a button action around it, similar to the way the slider action did.

robertiii

What cleanup would need to be done? I’m pretty much beginner coding.

robertiii

Also I’ve tried using the remove and have never been able to figure it out.