Play audio file stored in google drive (remote URL) - Swift - ios

I'm using AVPlayer to play audios which are stored in google drive. Problem is that as public link of files stored in google drive don't have extension mentioned, that's why AVPlayer doesn't play audio because cannot get its extension from URL. Following is code i'm using.
let url = URL(string: "https://drive.google.com/file/d/1n6GeWY11Txvou5K-Tl7Ju39fQsWQTDvR/view?usp=sharing")
let playerItem:AVPlayerItem = AVPlayerItem(url: url!)
player = AVPlayer(playerItem: playerItem)
player!.play()
For example, in case of following url
https://drive.google.com/file/d/1n6GeWY11Txvou5K-Tl7Ju39fQsWQTDvR/view?usp=sharing
AVPlayer isn't playing it and showing it's duration to 0.
But when i play audio file like following
https://www2.cs.uic.edu/~i101/SoundFiles/BabyElephantWalk60.wav
it plays without any problem because of file extension available.
So, could someone please comment how to play audio when extension not available in remote URLs.
Thanks

Just got to modify the URL, Use this:
https://drive.google.com/uc?export=open&id=1n6GeWY11Txvou5K-Tl7Ju39fQsWQTDvR
Here's what I did,
Sharing an audio file looks like this:
https://drive.google.com/file/d/XXXXXXXXXXXXXXXXXX/view?usp=sharing
XXXXXXXXXXXXXXXXXX is the file ID. You can access the direct file by getting rid of everything after the ID and replacing file/d/ with uc?export=open&id=
Keep in mind, if Google decide to change the way their file sharing works then this solution may break.

Related

AVPlayer with DocumentBrowserView

Good day.
Someone knows how to transfer the document url to the avplayer if you want to play the video file through DocumentBrowserView
Using documentUrl did not work for me

Unable to play firebase video on my iOS device

I have one simple application which is loading videos list from firebase and by click on any of the video I will load that video through AVPlayer.
But I am unable to play any video uploaded at Firebase storage.
Player Code :
func displayVideo(_ videoURL:URL){
let player = AVPlayer(url: videoURL as URL)
self.playerController.player = player
self.addChildViewController(self.playerController)
self.view.addSubview(self.playerController.view)
self.playerController.view.frame = self.view.frame
player.play()
}
Also, I tried another alternate solution by download this video locally and play it from local but that one also not working.
let me know if I am doing any mistake in the video player.
Guys no problem in my player code as I have test another video like test.mov file and its working in both solution.
Live streaming
Local file
So I found one answer here which help me to test my video formate.
Answer by Mike McDonald:
I have a feeling that the issue here is that the video is not in the
correct format (needs to be H.264 or MPEG-4 in .mp4, .m4v, .mov [or an
HLS video for live streaming]), and the content type should be set
appropriately (video/mp4, video/x-m4v, video/quicktime). Can you
confirm these?
Still for my satisfaction I have tried this video on Mac quick time player and got below error.
Than I realised that some time due to video formate we unable to play or stream video.
Thanks every one who helped here.
This answer is for whom who is facing same issue like me.

Play local video file without file extension iOS

I want to know if there is a possible way of playing a LOCAL video file which does not have an extension (eg. ".mp4") using the MPMoviePlayerViewController API.
If I try to play a video file without an extension using that API, it won't play it.
Can I possibly use the file mime-type to notify the MPMoviePlayerViewController of the file type ?
Changing the player API is not an option at the moment.

Download youtube video in iOS Swift

I am looking for solution to download video from youtube.
i saw in youtube native application in ios they are providing a feature to save video for offline.
Is there any solution to download video in application? Or any API to download video.
You can download video file from Youtube if we know youtube URL of the video. First you need to download files (HCYoutubeParser) into your project. Now you need to call following function into your code:
let video = HCYoutubeParser.h264videosWithYoutubeURL(yturl!)
let downloadURL = video["medium"] as! String
Where yturl is video URL. We need to pass it into h264videosWithYoutubeURL function. HCYoutubeParser is a class which provides methods for converting Youtube video watch URL into video download URL. This can be done by Youtube video id also. Following method is used for that:
let video = HCYoutubeParser.h264videosWithYoutubeID(ytID!)
let downloadURL = video["medium"] as! String
Where ytID is id of Youtube video. In these code snippet we are getting download URL of medium quality video. For more info and HCYoutubeParser class follow this link: http://findnerd.com/list/view/How-to-download-videos-from-YouTube-in-iOS/22437/
If you are looking for a library then XCDYouTubeKit would be a good choice. If you are looking for an open source app then YouTag might be helpful.

Play live URL streaming by AVPlayer

MY Real URL => "http://125.209.70.43:1500/"
As my title said that I want to play music from my live streaming URL. I tried with following code. (following URL is for testing not real)
[self playSelectedSong:#"http://media-ice.musicradio.com/HeartPlymouthV1"]; // custom method with testing URL
Code of method.
-(void)playSelectedSong:(NSString *) urlString
{
self.songPlayer = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]];;
[self.songPlayer play];
}
I have Question like.
1) What should proper URL Pattern? is streaming URL has any rules about its pattern or not ?
For example above code is woking for streaming URL (NOT mine url) such like,
1) http://108.178.57.196:11112/los40principales
2) http://media-ice.musicradio.com/HeartPlymouthV1
BUT in my URL it is not working (for iOS Devices), my URL pattern is
http://125.209.70.43:1500/
My streaming URL pattern looking like above.
Then how can I play music by using above URL ? My above code is not working for http://125.209.70.43:1500/. Anybody have issue related as a mine ?
Please help me on this issue.
NOTE: My URL is correct and its working, I checked with vlc media player network streaming. by
=> VLC Medial Player
-> File Menu
-> Open Network
-> URL set as "http://125.209.70.43:1500/"
-> click on "Open" button.
Try with above step it's working very well.
Your stream is Windows Media Audio, that's not going to work with AVPlayer. If you want to support streaming to iOS devices, check out https://developer.apple.com/streaming/

Resources