Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Hotshot10101 · Dec 05, 2014 at 12:22 AM · androidplayerpluginyoutube

YouTube Player Fragment in Plugin

I am trying to get a YouTube player to work in a Unity app.

I am using the Android API code and the YouTubePlayerFragment.

The player shows up just fine and plays the video, sort of. You can hear the audio and see the progress spinner, but when the video itself starts streaming all you see if the background image in Unity. If you sleep the phone and then wake it up you can then see the video.

If I do this exact same thing in an actual Android app it works fine.

I have tried everything I can think of. I have made the layout it is in have a background color and all kinds of stuff. I just can't get the video to show up right off.

Here is my code:

     private View getLeafView(View view) {
         if (view instanceof ViewGroup) {
             ViewGroup vg = (ViewGroup)view;
             for (int i = 0; i < vg.getChildCount(); ++i) {
                 View chview = vg.getChildAt(i);
                 View result = getLeafView(chview);
                 if (result != null) 
                     return result;
             }
             return null;
         }
         else {
             return view;
         }
     }
     
     public void Init(final String videoId, String objectName, final int heightOffset) {
         
         UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
             
             public void run() {
                 
                 _rootView = (ViewGroup)UnityPlayer.currentActivity.findViewById(android.R.id.content);
                 
                 // find the first leaf view (i.e. a view without children)
                 // the leaf view represents the topmost view in the view stack
                 View topMostView = getLeafView(_rootView);
                 
                 if (topMostView != null) {
                     
                     // let's add a sibling to the leaf view
                     ViewGroup leafParent = (ViewGroup)topMostView.getParent();
                 
                     if (leafParent != null) {
                         
                         LinearLayout.LayoutParams lpView = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                         lpView.weight = 1.0f;
                         lpView.gravity = Gravity.CENTER;
                         View view = new View(_context);
                         view.setLayoutParams(lpView);
                         
                         _layout = new LinearLayout(_context);
                         _layout.setOrientation(LinearLayout.VERTICAL);
                         _layout.setBackgroundColor(0xffffffff);
                         LinearLayout.LayoutParams lpLayout = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, leafParent.getWidth());
                         lpLayout.weight = 1.0f;
                         lpLayout.gravity = Gravity.CENTER;
                         
                         _layout.setLayoutParams(lpLayout);
                         
                         _layout.addView(view);
                         
                         _layout.setId(0x20348);
                         
                         YouTubePlayerFragment fragment = YouTubePlayerFragment.newInstance();
                         FragmentManager fragmentManager = UnityPlayer.currentActivity.getFragmentManager();
                         FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                         fragmentTransaction.add(_layout.getId(), fragment);
                         fragmentTransaction.commit();
 
                         _videoId = videoId;
                         
                         fragment.initialize(DEVELOPER_KEY,  _instance);
                         
                         leafParent.addView(_layout);
                     }
                 }
             }
         });
         
         UnitySend("Initialized");
     }
     
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Hampson · Mar 30, 2016 at 03:54 PM

From the Android Team:

"If the YouTube player is going to cover the unity surface I would suggest you put the youtube widget either in a separate activity or inside a dialog frame. That way you can avoid sorting the surfaces and rely on android to do the correct thing"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

26 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Homebase SDK android Plugin Help 0 Answers

Bad performance on quad core Android phones 0 Answers

Android Unity Plugin problem 0 Answers

Turn your Android device webcam (Camera) , flash light 3 Answers

android - native twitter connect 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges