高通AR加视屏解决方案

来源:互联网 发布:如何下载会声会影软件 编辑:程序博客网 时间:2024/05/16 02:22

按到以下教程制作出现以下问题

1、视频不能播放

解决方案:1、加入SceneManager 2、给ARCamera加上PlayVideo.cs

问题2:勾选auto play后,还是不能自动播放

解决方案:给ImageTarget 加上 TrackableEventHandler.cs


2、加入SceneManager了后,在启动软件时有高通的介绍和设置之类的,要取消的话在代码中改,注销红色部分即可

AppManager.cs

 public virtual void InitManager()
    {
        mSplashView = new SplashScreenView();
        mAboutView = new AboutScreenView();
        mAboutView.SetTitle(TitleForAboutPage);
        mAboutView.OnStartButtonTapped += OnAboutStartButtonTapped;
        m_UIEventHandler.CloseView += OnTappedOnCloseButton;
        m_UIEventHandler.GoToAboutPage += OnTappedOnGoToAboutPage;
        InputController.SingleTapped += OnSingleTapped;
        InputController.DoubleTapped += OnDoubleTapped;
        InputController.BackButtonTapped += OnBackButtonTapped;

        //mSplashView.LoadView();
        //StartCoroutine(LoadAboutPageForFirstTime());

        mActiveViewType = ViewType.SPLASHVIEW;
    }


前段时间忙公司的事,好久没到CSDN来了,看到教程有这么多人参考,决心再接再厉,这篇教程就讲讲怎么做video形式的增强现实。(自己做了个案例,少女时代著名的甩大腿舞戳我O(∩_∩)O)

高通的SDK好像没有video的预制件,所以我一般都下载最新的samples,里面有我们需要用到的预制件。高通官网下载:


将包导入unity,大家可以选择自行研究例子,理清制作思路,当然也可以直接利用我总结出来的方法制作。

1、和之前介绍的AR制作一样,首先删掉main camera,在Assets搜索AR Camera并将其拖到Hierarchy,同样的将ImageTarget也拖进来,对ImageTarget参数进行修改,这里我使用例子里的识别图。

2、在assets里找到video这个预制件,将他拖到imagetarget下作为子物体。


3、 修改video的参数,path是视频的名字加后缀,例如:VuforiaSizzleReel_1.m4v,因为视频一般较大,所以建议大家将视频格式转为3g2,可以大大压缩视频所占空间,唯一的缺点是不能在电脑上测试。


4、 最重要的问题,vuforia如何找到视频的路径?答案是,视频必须放在指定文件夹下,当然可以到代码修改文件夹。默认的是StreamingAssets文件夹下


5、其他的操作,如需控制视频播放,比如识别图移出摄像头,然后再次识别,视频是从头开始播放还是从上一次的位置播放呢?大家自行阅读VideoPlaybackBehaviour这个脚本,然后修改代码就可以了~\(≧▽≦)/~啦啦啦

以上教程原地址:http://blog.csdn.net/dzyi_/article/details/34847339


按照原作者的想法,是可以实现手机观察到播放封面,但没法点击播放。针对这个问题,我翻看了官方论坛,因为最新的unity包缺少了一个C#文件。把缺少的文件加上,可以实现播放,以下为详细说明:

The objective here is to show how to replicate the essence of the Vuforia-VideoPlayback sample scene using the Vuforia prefabs and the drag and drop approach of Unity:

  • Create a new Unity project
  • Import the Vuforia video playback unity package
  • Create a new scene
  • Drag the ARCamera prefab into the Unity scene
  • Under the DataSetLoadBehaviour in the Inspector tick “Load Data Set StonesAndChips”, and the 'Activate' checkbox below this
  • From '/Qualcomm AugmentedReality/Prefabs' drag the ImageTarget prefab into the scene
    • For the Image Target select “StonesAndChips” as the dataset and the Image Target should change to the Stones texture
  • From Vuforia Video Playback/Prefabs drag the Video prefab to be the child of the Image Target
    • In the Inspector under “Video Playback Behaviour (Script)” set the path to 'VuforiaSizzleReel_1.m4v'
  • Drag the TrackableEventHandler from Scripts to the Image Target (this plays the video)
  • Remove the DefaultTrackableEventHandler script from the Image Target as it is not needed.
  • Autoplay works already, however tapping the video does not yet work. In order to fix this, simply create a VideoPlaybackController script, fill it with the code below, and then attach this to the ARCamera.

       大概意思就是(我英语不好,懂意思就好= =#,英语好的还是读上文吧):

  • 创建一个新的Unity工程
  • 引入Vuforia video playback的unity包
  • 创建一个新的场景
  • 拖ARCamera进场景(ARCamera搜索下很好找到)
  • 点击场景中的ARCamera,右边Inspector栏目,DataSetLoadBehaviour(script)中“Load Data Set StonesAndChips”和 'Activate'都打上勾
  • 从'/Qualcomm AugmentedReality/Prefabs'目录中Image Target拖入场景,右边Data Set选择“StonesAndChips”
  • 从“Vuforia Video Playback/Prefabs”目录中Video拖入场景,右边“Video Playback Behaviour (Script)”中path栏输入'VuforiaSizzleReel_1.m4v'(测试是播放这个视频),或者也可以使用
    [html] view plaincopy
    1. http://oneshot.qualcomm.com/webAR/content/strawberryfields_H264_AAC.mp4  
    这个网络视频进行测试

  • 把TrackableEventHandler这个C#文件放到Image Target中,主要是用来播放视频的
  • 从Image Target中移除DefaultTrackableEventHandler这个文件的使用,因为这个文件根本不需要,移除的话其实把它的打勾去掉也可以
  • 自动播放要不要打上勾随自己需要,   创建VideoPlaybackController的C#文件放入ARCamera中,VideoPlaybackController中的代码如下:


[csharp] view plaincopy
  1. /*============================================================================== 
  2. Copyright (c) 2012-2014 Qualcomm Connected Experiences, Inc. 
  3. All Rights Reserved. 
  4.   
  5. This  Vuforia(TM) sample application in source code form ("Sample Code") for the 
  6. Vuforia Software Development Kit and/or Vuforia Extension for Unity 
  7. (collectively, the "Vuforia SDK") may in all cases only be used in conjunction 
  8. with use of the Vuforia SDK, and is subject in all respects to all of the terms 
  9. and conditions of the Vuforia SDK License Agreement, which may be found at 
  10. <a title="https://developer.vuforia.com/legal/license" href="https://developer.vuforia.com/legal/license">https://developer.vuforia.com/legal/license</a>. 
  11.   
  12. By retaining or using the Sample Code in any manner, you confirm your agreement 
  13. to all the terms and conditions of the Vuforia SDK License Agreement.  If you do 
  14. not agree to all the terms and conditions of the Vuforia SDK License Agreement, 
  15. then you may not retain or use any of the Sample Code in any manner. 
  16. ==============================================================================*/  
  17.    
  18. using UnityEngine;  
  19. using System.Collections;  
  20.    
  21. /// <summary>  
  22. /// This class contains the logic to handle taps on VideoPlaybackBehaviour game objects  
  23. /// and starts playing the according video. It also pauses other videos when a new one is  
  24. /// started.  
  25. /// </summary>  
  26. public class VideoPlaybackController : MonoBehaviour  
  27. {  
  28.     #region PRIVATE_MEMBER_VARIABLES  
  29.    
  30.     private Vector2 mTouchStartPos;  
  31.     private bool mTouchMoved = false;  
  32.     private float mTimeElapsed = 0.0f;  
  33.    
  34.     private bool mTapped = false;  
  35.     private float mTimeElapsedSinceTap = 0.0f;  
  36.    
  37.     private bool mWentToFullScreen = false;  
  38.   
  39.     #endregion // PRIVATE_MEMBER_VARIABLES  
  40.   
  41.   
  42.   
  43.     #region UNITY_MONOBEHAVIOUR_METHODS  
  44.    
  45.     void Update()  
  46.     {  
  47.         // Determine the number of taps  
  48.         // Note: Input.tapCount doesn't work on Android  
  49.    
  50.         if (Input.touchCount > 0)  
  51.         {  
  52.             Touch touch = Input.touches[0];  
  53.             if (touch.phase == TouchPhase.Began)  
  54.             {  
  55.                 mTouchStartPos = touch.position;  
  56.                 mTouchMoved = false;  
  57.                 mTimeElapsed = 0.0f;  
  58.             }  
  59.             else  
  60.             {  
  61.                 mTimeElapsed += Time.deltaTime;  
  62.             }  
  63.    
  64.             if (touch.phase == TouchPhase.Moved)  
  65.             {  
  66.                 if (Vector2.Distance(mTouchStartPos, touch.position) > 40)  
  67.                 {  
  68.                     // Touch moved too far  
  69.                     mTouchMoved = true;  
  70.                 }  
  71.             }  
  72.             else if (touch.phase == TouchPhase.Ended)  
  73.             {  
  74.                 if (!mTouchMoved && mTimeElapsed < 1.0)  
  75.                 {  
  76.                     if (mTapped)  
  77.                     {  
  78.                         // Second tap  
  79.                         HandleDoubleTap();  
  80.                         mTapped = false;  
  81.                     }  
  82.                     else  
  83.                     {  
  84.                         // Wait to see if this is a double tap  
  85.                         mTapped = true;  
  86.                         mTimeElapsedSinceTap = 0.0f;  
  87.                     }  
  88.                 }  
  89.             }  
  90.         }  
  91.    
  92.         if (mTapped)  
  93.         {  
  94.             if (mTimeElapsedSinceTap >= 0.5f)  
  95.             {  
  96.                 // Not a double tap  
  97.                 HandleTap();  
  98.                 mTapped = false;  
  99.             }  
  100.             else  
  101.             {  
  102.                 mTimeElapsedSinceTap += Time.deltaTime;  
  103.             }  
  104.         }  
  105.    
  106.         // special handling in play mode:  
  107.         if (QCARRuntimeUtilities.IsPlayMode())  
  108.         {  
  109.             if (Input.GetMouseButtonUp(0))  
  110.             {  
  111.                 if (PickVideo(Input.mousePosition) != null)  
  112.                     Debug.LogWarning("Playing videos is currently not supported in Play Mode.");  
  113.             }  
  114.         }  
  115.     }  
  116.   
  117.     #endregion // UNITY_MONOBEHAVIOUR_METHODS  
  118.   
  119.   
  120.   
  121.     #region PRIVATE_METHODS  
  122.    
  123.     /// <summary>  
  124.     /// Handle single tap event  
  125.     /// </summary>  
  126.     private void HandleTap()  
  127.     {  
  128.         // Find out which video was tapped, if any  
  129.         VideoPlaybackBehaviour video = PickVideo(mTouchStartPos);  
  130.    
  131.         if (video != null)  
  132.         {  
  133.             if (video.VideoPlayer.IsPlayableOnTexture())  
  134.             {  
  135.                 // This video is playable on a texture, toggle playing/paused  
  136.    
  137.                 VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus();  
  138.                 if (state == VideoPlayerHelper.MediaState.PAUSED ||  
  139.                     state == VideoPlayerHelper.MediaState.READY ||  
  140.                     state == VideoPlayerHelper.MediaState.STOPPED)  
  141.                 {  
  142.                     // Pause other videos before playing this one  
  143.                     PauseOtherVideos(video);  
  144.    
  145.                     // Play this video on texture where it left off  
  146.                     video.VideoPlayer.Play(false, video.VideoPlayer.GetCurrentPosition());  
  147.                 }  
  148.                 else if (state == VideoPlayerHelper.MediaState.REACHED_END)  
  149.                 {  
  150.                     // Pause other videos before playing this one  
  151.                     PauseOtherVideos(video);  
  152.    
  153.                     // Play this video from the beginning  
  154.                     video.VideoPlayer.Play(false, 0);  
  155.                 }  
  156.                 else if (state == VideoPlayerHelper.MediaState.PLAYING)  
  157.                 {  
  158.                     // Video is already playing, pause it  
  159.                     video.VideoPlayer.Pause();  
  160.                 }  
  161.             }  
  162.             else  
  163.             {  
  164.                 // Display the busy icon  
  165.                 video.ShowBusyIcon();  
  166.                    
  167.                 // This video cannot be played on a texture, play it full screen  
  168.                 video.VideoPlayer.Play(true, 0);  
  169.                 mWentToFullScreen = true;  
  170.             }  
  171.         }  
  172.     }  
  173.    
  174.    
  175.     /// <summary>  
  176.     /// Handle double tap event  
  177.     /// </summary>  
  178.     private void HandleDoubleTap()  
  179.     {  
  180.         // Find out which video was tapped, if any  
  181.         VideoPlaybackBehaviour video = PickVideo(mTouchStartPos);  
  182.    
  183.         if (video != null)  
  184.         {  
  185.             if (video.VideoPlayer.IsPlayableFullscreen())  
  186.             {  
  187.                 // Pause the video if it is currently playing  
  188.                 video.VideoPlayer.Pause();  
  189.    
  190.                 // Seek the video to the beginning();  
  191.                 video.VideoPlayer.SeekTo(0.0f);  
  192.    
  193.                 // Display the busy icon  
  194.                 video.ShowBusyIcon();  
  195.    
  196.                 // Play the video full screen  
  197.                 video.VideoPlayer.Play(true, 0);  
  198.                 mWentToFullScreen = true;  
  199.             }  
  200.         }  
  201.     }  
  202.    
  203.    
  204.     /// <summary>  
  205.     /// Find the video object under the screen point  
  206.     /// </summary>  
  207.     private VideoPlaybackBehaviour PickVideo(Vector3 screenPoint)  
  208.     {  
  209.         VideoPlaybackBehaviour[] videos = (VideoPlaybackBehaviour[])  
  210.                 FindObjectsOfType(typeof(VideoPlaybackBehaviour));  
  211.    
  212.         Ray ray = Camera.main.ScreenPointToRay(screenPoint);  
  213.         RaycastHit hit = new RaycastHit();  
  214.    
  215.         foreach (VideoPlaybackBehaviour video in videos)  
  216.         {  
  217.             if (video.collider.Raycast(ray, out hit, 10000))  
  218.             {  
  219.                 return video;  
  220.             }  
  221.         }  
  222.    
  223.         return null;  
  224.     }  
  225.    
  226.    
  227.     /// <summary>  
  228.     /// Pause all videos except this one  
  229.     /// </summary>  
  230.     private void PauseOtherVideos(VideoPlaybackBehaviour currentVideo)  
  231.     {  
  232.         VideoPlaybackBehaviour[] videos = (VideoPlaybackBehaviour[])  
  233.                 FindObjectsOfType(typeof(VideoPlaybackBehaviour));  
  234.    
  235.         foreach (VideoPlaybackBehaviour video in videos)  
  236.         {  
  237.             if (video != currentVideo)  
  238.             {  
  239.                 if (video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)  
  240.                 {  
  241.                     video.VideoPlayer.Pause();  
  242.                 }  
  243.             }  
  244.         }  
  245.     }  
  246.   
  247.     #endregion // PRIVATE_METHODS  
  248.   
  249.   
  250.   
  251.     #region PUBLIC_METHODS  
  252.    
  253.     /// <summary>  
  254.     /// One-time check for the Instructional Screen  
  255.     /// </summary>  
  256.     public bool CheckWentToFullScreen()  
  257.     {  
  258.         bool result = mWentToFullScreen;  
  259.         mWentToFullScreen = false;  
  260.         return result;  
  261.     }  
  262.   
  263.     #endregion // PUBLIC_METHODS  
  264. }  




2 0
原创粉丝点击