toshi0383 / TVMLKitchen

Swifty TVML template manager with or without client-server
MIT License
81 stars 12 forks source link

Can it play videos? #128

Closed Wei-Xia closed 7 years ago

Wei-Xia commented 7 years ago

Hello,

I use SampleRecipe in my Swift tvOS app. It can load TVML file from raw XML String, however it can't play videos?

Anyone knows how to solve it? Thanks!

btw, happy new year!

toshi0383 commented 7 years ago

Hello @Wei-Xia ! Can you show your xml?

Wei-Xia commented 7 years ago

Hello @toshi0383 ,

Below is my code. I believe my code works well with TVML. Please let me know if you feel anything confused. Thank you! 😅

<?xml version="1.0" encoding="UTF-8" ?>
<document>
    <head>
        <style>
            .badge {
            tv-tint-color: rgb(255,255,255);
            }
            .button {
            font-size: 100px;
            }
        </style>
    </head>
    <compilationTemplate theme="dark">
        <list>
            <relatedContent>
                <itemBanner>
                    <heroImg src="((MAIN_BUNDLE_URL))home.jpg" width="800" height="800" />
                </itemBanner>
            </relatedContent>
            <header>
                <title>Title</title>
                <subtitle>Series</subtitle>
                <row  class="subtitle">
                    <text>39 minutes</text>
                    <badge src="resource://hd" class="badge"/>
                </row>
            </header>
            <section>
                <description allowsZooming="true">This is a description</description>
            </section>
            <section>
                <listItemLockup videoURL="http://www.rwdevcon.com/videos/Ray-Wenderlich-Teamwork.mp4">
                    <ordinal minLength="4">1</ordinal>
                    <title>Title</title>
                    <decorationLabel>04:10</decorationLabel>
                </listItemLockup>
            </section>
        </list>
    </compilationTemplate>
</document>
toshi0383 commented 7 years ago

Thanks for providing sample code @Wei-Xia . I believe you're following this RW's tutorial. videoURL is a custom attribute handled by the JS code from the tutorial, not by TVMLKit. With TVMLKitchen, the JS code part is currently all embedded in the kitchen.js .

I think you can use Kitchen's action API, to push an AVPlayerViewController onto appController's navigationController.

Wei-Xia commented 7 years ago

Hi @toshi0383 , Thanks for your response!

Yes, I do follow the tutorial on that website for personal interest.

I still feel confused about your answer, probably I am a newbie to tvOS. You mean JS part is already embedded in kitchen.js. Can you tell me how to call action API in order to play the videos? Thank you! 😬😬

toshi0383 commented 7 years ago

Sure! I will create a movie playback sample.

toshi0383 commented 7 years ago

@Wei-Xia kitchen.js is not ought to edited by users (though it can be, since it's embedded as plain text file.), so users cannot add any custom attributes. Kitchen already handles actionID and playActionID as documented here. So you can set a callback function for yourself. Just added a MoviePlaybackSample target in #129 . Please take a look. I hope this helps you.

toshi0383 commented 7 years ago

In case you need to handle play/pause button, you can use playActionIDHandler. Take a look at #130 .

Wei-Xia commented 7 years ago

@toshi0383 Thank you for providing such a great MoviePlaybackSample for me!

Since I'm using Swift 2.2 to develop my tvOS app and you are using Swift 3, I have already converted some parts of your code in AppDelegate.swift into Swift 2.2.

I will submit a PR in case some people are using Swift 2.2.

Also, I found a small issue while playing video. The screen won't play the video automatically unless user presses start button (In Xcode Simulator, I need to press Space in order to start).

toshi0383 commented 7 years ago

Thank you for providing such a great MoviePlaybackSample for me!

Happy to help!

I will submit a PR in case some people are using Swift 2.2.

That would be great! If you do so, please rebase it to swift2.2 branch.

Also, I found a small issue while playing video. The screen won't play the video automatically unless user presses start button (In Xcode Simulator, I need to press Space in order to start).

Thanks for reporting. I guess that's how AVPlayerViewController works. You can manually tell AVPlayer to start.

            Kitchen.navigationController.pushViewController(vc, animated: true)
            vc.player?.play()
Wei-Xia commented 7 years ago

Sure, I will rebase to swift2.2 over this weekend. 😁

With vc.player?.play(), my tvOS app can automatically play the videos. Thank you so much for your help. Your clarification is super clear and understandable! Appreciate it!

I think you can close this issue as it is successfully resolved. 😄