Can I play a youtube video in a UIWebView inline (not fullscreen)? - uiwebview

I have looked everywhere on how to do this and haven't found an answer yet.
Is it possible to play a youtube video in a UIWebView on an iPhone inline, i.e. not fullscreen?
I know that the iPhone doesn't support flash, but youtube supports html5 and has h.264 videos doesn't it? shouldn't I be able to do this then?
I have set allowsInlineMediaPlayback to YES, but still it plays fullscreen.

Yes you can, you need to set property on UIWebView
webView.allowsInlineMediaPlayback=YES;
And you need to add &playsinline=1 to YouTube iframe embedding code.
<iframe webkit-playsinline width="200" height="200" src="https://www.youtube.com/embed/GOiIxqcbzyM?feature=player_detailpage&playsinline=1" frameborder="0"></iframe>
Tested on iPhone 4S running iOS 6.1.2 works like a charm.

allowsInlineMediaPlayback UIWebView properties
Boolean value that determines whether HTML5 videos play inline or use the native full-screen controller. (developer.apple.com)
You can use this feature on iPad. On the iPhone there is no such function. If you try play video with uiwebview on iPhone it will be played in full screen mode.

Yes, you can play any embed video inline UIWebView itself with help of "playsinline=1".
Source code like:
NSMutableString *html = [[NSMutableString alloc] initWithCapacity:1] ;
[html appendString:#"<html><head>"];
[html appendString:#"<style type=\"text/css\">"];
[html appendString:#"body {"];
[html appendString:#"background-color: transparent;"];
[html appendString:#"color: white;"];
[html appendString:#"}"];
[html appendString:#"</style>"];
[html appendString:#"</head><body style=\"margin:0\">"];
[html appendString:#"<iframe webkit-playsinline width=\"300\" height=\"220\" src=\"http://www.ustream.tv/embed/23192315?html5ui&showtitle=false&playsinline=1\" frameborder=\"0\"></iframe>"];
[html appendString:#"</body></html>"];
[self.webViewRef loadHTMLString:html baseURL:nil];

Related

medialement.js not working for my hls on iphone

Here is my m3u8 file:
cat 8.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-MEDIA-SEQUENCE:1131
#EXT-X-TARGETDURATION:5
#EXTINF:4.950, no desc
1545049888215.ts
#EXTINF:4.950, no desc
1545049893218.ts
I serve it at as static file at http://104.248.205.68:31339/8.m3u8
I use mediaelemnts.js to run this hls video: jsfiddle
html:
<video width="240" height="160"
id="player1" src="http://104.248.205.68:31339/8.m3u8"
controls="controls" autoplay preload="auto" muted ></video>
js:
$('video').mediaelementplayer({});
It works fine on chrome mac os desktop. But not working on iphone 8+ (safari and chrome). No errors in the console. Video just not played, black screen. In the fullscreen mode of video - the same.
At the same time, if I find a random m3u8 on the internet and use mediaelemnts.js to play it, it works well on the iPhone (at least in fullscreen mode) jsfiddle 2.
So I guess something wrong with my m3u8 file since other m3u8s are runnable on the iPhone.
If I open network tab while loading the problem page on Iphone, I see it's downloading the files but not showing video for some reason.
Update
I checked on android: galaxy s5 and galaxy s9+ in chrome: both works.
Update 2
Zip archive with ts files and m3u8: http://104.248.205.68:31339/8.m3u8.zip
When inspecting the media files [1] it can be found that the PMT (Program Map Table) signals that there is audio in the stream, but there are actually no TS packets for audio (i.e. no audio data) present.
It looks like the player waits for the audio TS packets in order to build a common buffer for both, audio and video, and only then start playback. Since the stream lacks audio data that never happens. To back that up, you can use ffmpeg to remove the audio track from the media segments using the below command and find that playback would work once you do this.
ffmpeg -i 1545049893218.ts -an -vcodec copy 1545049893218-v.ts
Further, the reason this problem only manifests in Safari and Chrome on iOS is that in those cases mediaelement.js is using the browser's native capabilities to play HLS, instead of a JavaScript player (like hls.js) which is used on other platforms (e.g. Chrome on desktop) and is more tolerant to such problem cases.
[1] E.g. using http://thumb.co.il/ or ffprobe
EDIT:
While the above may be sufficient to make it work on older Apple mobile devices - I tested on iPhone 6 iOS10 - newer devices seem to be more restrictive. The official HLS Authoring Spec states
8.11. You MUST provide at least 6 segments in a live/linear playlist.
which does not seem to be a hard requirement on some iOS versions. However, to ensure it to be working on all versions these requirements should be met.
I did a quick test on iPhone X with iOS12 and found it would play if at least 3 segments are provided in the playlist by just duplicating the last segment entry.

How to play YouTube video in WebView on Google Glass

I have code like this:
setContentView(R.layout.webview);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("https://www.youtube.com/watch?v=_Z5-P9v3F8w");
It'll show the youtube video with the Play button, but none of the Glass gesture can make the video play. Any ideas? Thanks!
Finally figured out how to play Youtube video on Glass!
Intent i = new Intent();
i.setAction("com.google.glass.action.VIDEOPLAYER");
i.putExtra("video_url", "https://m.youtube.com/watch?v=5bWSgFnoCOk");
startActivity(i);
Using WebView can't play the video, using VideoView can only play local MP4 or streaming MP4 (there's some way to hack the MP4 link for a Youtube video, but not reliable). Also, using VideoView can only pause/play the video, but not fast forward or backward. Using the com.google.glass.action.VIDEOPLAYER above solves all the problems WebView and VideoView have.

MPMediaItemPropertyAssetURL becomes null when Using MPMediaItems to play songs

I am implementing a Music related Application. In my application I need to use AVPlayer instead of MPMusicPlayer to play iPod Library songs. I used AVPlayer to support FadeIn and Fadeout effects for the background playback of MPMediaItems. I used MPMediaItemProperyAssetURL to get the url from the MPMediaItem and give it as input to the AVPlayer like follows. My problem is some items are won't play because of null url. I found that songs downloaded from iTunes store (which are DRM protected) were unable to play because they have no MPMediaItemProperyAssetURL. Could you please guys help me, how can I resolve these issues. I need to support these DRM protected songs in AVPlayer. Please take a look at my following code for reference,
MPMediaItem *currentItem = [songs objectAtIndex:songIndex];
NSURL *itemURL = [currentItem valueForProperty:MPMediaItemPropertyAssetURL];
currentlyPlayingItem=[itemURL absoluteString];
avPlayer = [[AVPlayer alloc] initWithURL:itemURL];
[avPlayer play];
Thanks in Advance,
Sekhar.
Regrettably there is no mechanism to load DRM'd files into the AVPlayer or any of the AV Foundation APIs. If you can convince your users to upgrade their entire library at $0.30 per song with iTunes Plus, that is the only way.

No audio on iPad with MPMoviePlayerViewController and iOS5, works in the simulator

Ever since I updated to iOS 5, I can't get MPMoviePlayerViewController to play audio on the iPad. Video is perfect, but no audio is heard. It doesn't matter what format I use. It does not work. It works in the simulator, but not on the iPad.
- (IBAction)playVideo {
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:#selector(movieFinishedPlaying:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[moviePlayer moviePlayer]];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
Anyone else have this problem? Or found a fix?
It sounds silly, but we came across an issue on my team where the volume control for general iPad sounds was muted and this meant that there was no sound for video played in our app, even though music played through the music player or video on websites worked fine.
To check this volume control you can bring up the task manager (double-tap the home button) and then swipe across to the far left and there are some music controls; check that the mute button on this screen is not on.
try this:
...
moviePlayer.useApplicationAudioSession = NO;
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
set audio session before allocating MPMoviePlayerController will play sound along with video
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
Ensure the audio format in the video file is something that the iPad can play. I believe the simulator has access to the host machine's codecs, which might explain why the iPad can play the video but not the audio. As noted on this page in the MPMoviePlayerController documentation:
If you use this class to play audio files, it displays a white screen with a QuickTime logo while the audio plays. For audio files, this class supports AAC-LC audio at up to 48 kHz, and MP3 (MPEG-1 Audio Layer 3) up to 48 kHz, stereo audio.
I just made the slide button on the side into lock screen. Then the sound suddely worked.

Best way to play wav files in the browser?

I have no choice but to play wav files directly in the browser (serverside encoding to mp3 isn't an option, unfortunately.)
What's the best way to do this? I'd really like to take advantage of the HTML 5 audio tag but my target audience includes many, many teens using IE6. As far as I'm aware flash isn't an option, but speedy playback really is critical.
Thanks.
Nowadays, the best way is probably just to use the HTML5 <audio> tag. In the past, you might have done it like this:
Background:
<embed src="bgsound.wav" hidden="true" autostart="true" loop="1">
On Click:
Play Sound
It's been a few years since the last answer. Embed tag was good but I had an issue trying to trigger it to play in JavaScript. New audio tag works well is most browsers.
<audio src="cat9.wav" preload></audio>
You can trigger it manually with audioElement.play()
<audio controls="controls"><source src="http://blablabla.com/hghghgh/my%20file.wav" type="audio/x-wav" /></audio>
Due to unfixed bug (issue from 2012 year?) sometimes Chromium-like browsers cannot play .wav from redirected URLs because they "think" that file size is zero. But .mp3 is OK.
Opera 12.14 and Firefox play from < audio >
tag normally in the same case (redirected URL).
I tried JPlayer's 2.9.* lib in Drupal 7 with 3 players, but not successful (was black inactive rectangle 300*14 pixels for each player).

Resources