- Home /
Videos Failing to play from Application.persistentDataPath on Google Pixel Phones
I am unable to play videos from the persistentDataPath directory after downloading them from a server. It works fine on most Android devices, but it's not working on Google Pixel phones. Videos just immediately finish playing without starting, and they prepare forever. Downloading Part:
     public void downloadVideo(string url, string nameWithExtension)
     {
         string localVideoDirectory = System.IO.Path.GetFileNameWithoutExtension(nameWithExtension) + ".mp4";
         filePath = System.IO.Path.Combine(Application.persistentDataPath, localVideoDirectory);
         StartCoroutine(DownloadVideo());
         Debug.LogWarning("file path in downloading: " + filePath);
     }
 
     IEnumerator DownloadVideo()
     {
         Debug.Log("VideoFileDownloader_DownloadVideo_URL: " + URL);
 
         downloader = UnityWebRequest.Get(URL);
         downloader.chunkedTransfer = false;
         yield return (operation=downloader.SendWebRequest());
 
         if (downloader.isNetworkError || downloader.isHttpError)
         {
             Debug.LogError(downloader.error);
         }
         else
         {
             downloaderPanel.SetActive(false);
             isDownloadComplete = true;
             Debug.Log("VideoFileDownloader_video_size " + downloader.downloadedBytes);
             Debug.Log("Download completed successfully");
             File.WriteAllBytes(Path.Combine(Application.persistentDataPath, filePath), downloader.downloadHandler.data);
         }
     }
Video Playback:
 IEnumerator playVideo() { 
         isVideoPaused = false;
         isVideoActivated = true;
         VideoLoadingPanel.SetActive(true);
 
         //We want to play from url
         videoPlayer.source = VideoSource.Url;
         videoPlayer.url = URL;
         videoPlayer.Prepare();
         preparationTimer = 0f;
 
         yield return new WaitUntil(() => videoPlayer.isPrepared || preparationTimer >= 5.0f);
 
 
         Debug.Log("Done Preparing Video in: " + preparationTimer + "seconds");
 
         Debug.Log("Video URL: " + URL);
         //here, we prepared our video, now we switch to the video canvas
 
         //main canvas is at 0, so this makes the video canvas visible
         //yield return null;
         //videoCanvas.sortingOrder = 1;
         //Play Video
         videoPlayer.Play();
         VideoLoadingPanel.SetActive(false);
 
         Debug.Log("Playing Video");
         while (videoPlayer.isPlaying)
         {
             Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)videoPlayer.time));
             yield return null;
         }
 
         yield return new WaitUntil(() => videoPlayer.isPlaying == false && isVideoPaused == false);
         //yield return new WaitForSeconds(0.3f);
         isVideoActivated = false;
 
         videoPlayer.Stop();
         clearRenderTexture();        //disable raw image
         //rawImage.gameObject.SetActive(false);
         videoCanvas.sortingOrder = -1; //show it behind the main canvas
         Debug.Log("Done Playing Video");
         Screen.sleepTimeout = (int)SleepTimeout.SystemSetting;
 
     }
Any ideas? Let me know if you have any questions.
Thanks.
Your answer
 
 
             Follow this Question
Related Questions
Could a privacy error on a video streaming server cause videos not to play in an Android build? 1 Answer
Is it possible to access a file from the android Internal storage on to a Unity app during run time? 0 Answers
Handheld.PlayFullScreenMovie memory leak? 1 Answer
Error loading video from custom local url and playing it using VideoPlayer component 1 Answer
android display h264 byte[] stream 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                