How to hide "Now playing url" in control center - ios

I am trying to hide livestream urls that are playing in an UIWebView.
When you play a livestream url and open control center (iOS) you see the url that is playing:
.
I would like to hide that with a HTML-based or xcode-based script.

You can control this information with the MPNowPlayingInfoCenter. The defaultCenter's nowPlayingInfo dictionary controls what is displayed about the current audio track on the lock screen and command center.
MPNowPlayingInfoCenter *infoCenter = [MPNowPlayingInfoCenter defaultCenter];
NSDictionary *nowPlayingInfo = #{
MPMediaItemPropertyTitle : #"Media Name",
MPMediaItemPropertyArtist : #"Media Artist"
};
[infoCenter setNowPlayingInfo:[NSDictionary dictionaryWithDictionary:nowPlayingInfo]];
The full list of keys are listed in the docs, but it looks like you want to set the track name to the empty string.
MPMediaItemPropertyTitle : #""

Related

WKWebView media controls title displays Url

Is it possible to change the iOS media controls (lock screen, command center media) title from the Url when playing a video from WKWebView?
I have tryied the following and cannot get Now Playing info to change:
DispatchQueue.main.async() {
var nowPlayingInfo = [String : Any]()
nowPlayingInfo[MPMediaItemPropertyTitle] = "Some title"
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
Using https://www.youtube.com/iframe_api onYouTubeIframeAPIReady I can get the title and send it back to the app, but the issue is getting the now applying controls to update the title from the video Url.
The MPNowPlayingInfoCenter displays the title of the webpage as title of the currently played audio/video.
Since the homepage title is never visible in the webview, you can freely change it via Javascript as soon as a new audio or video file is played:
document.title = "your title";
The new homepage title will now be displayed on your NowPlayingInfoCenter as currently playing audio/video.
Works great for me.
You could also do it inside the app code (Objective-C):
[webView evaluateJavaScript:#"document.title = \"your title\";" completionHandler:nil];

How to post a video selected from the library on an apple device to a view controller in xcode using swift

I would like to choose a video from the library(which I have completed) NOW, I want to take that video and display it in a view controller. What do I do? I have looked everywhere and have found nothing.
Here is my code for trying to get the file name of a selected video from the library, which I am trying to display in a webview. It does not work.
videoURL = info[UIImagePickerControllerReferenceURL] as! NSURL?
let fileURL = NSURL(fileURLWithPath: " (videoURL)")
videoView.loadHTMLString( " ", baseURL : nil)
Any help is much appreciated. Thanks!
You'll need to implement the delegate methods.. Check this out:
How to select any Video or Movie file from UIImagePickerController

iOS: Get the length of the song from parse

I have uploaded few files on parse framework and I am live streaming those files and play them in AVPlayer.
let url = currentAudioPath
let playerItem = AVPlayerItem( URL:NSURL( string:url ) )
player1 = AVPlayer(playerItem:playerItem)
player1.rate = 1.0;
self.configurePlayer()
player1.play()
I have not downloaded the entire file at once. But is there a way to retrieve the length of the song?
"AVPlayerItem" has a ".duration" property that might help you.
Look at the notes though: You won't be able to get the duration "until the status of the AVPlayerItem is AVPlayerItemStatusReadyToPlay." You could also set a KVO on the property so you could update your UI once the item duration is determined by the AVFoundation layer.

Playback restricted on iOS for VEVO videos from YouTube API

I have embedded videos (pulled from YouTube API v3) into my iPhone app using a UIWebView as suggested. The problem is that some videos, such as those from VEVO, produce the following error when attempting to play them on the device.
This video contains content from VEVO. It is restricted from playback on certain sites.
This should not occur, since apps like Flipboard and Rockpack also seem to be using a UIWebView, and are able to play videos from VEVO and other sources.
What could I be doing wrong?
PS: I am aware that there exist other posts that touch upon this issue in some way, but they fail to address this specific problem.
Using YouTube's YTPlayerView for iOS and setting the origin property to a valid URL allows many VEVO videos to be played properly.
In your View Controller:
#property (weak, nonatomic) IBOutlet YTPlayerView *playerView;
// ..
NSDictionary *playerVars = #{
#"playsinline" : #1,
#"showinfo" : #0,
#"rel" : #0,
#"controls" : #1,
#"origin" : #"https://www.example.com", // this is critical
#"modestbranding" : #1
};
[self.playerView loadWithVideoId:#"Ri7-vnrJD3k" playerVars:playerVars];
With origin:
Without origin:
Are you getting the error on all videos from VEVO?
Are you sure the video you're trying to play is embeddable?
Add the 'videoEmbeddable' parameter with the 'true' value so you're only working with videos you can embed.
The videoEmbeddable parameter lets you to restrict a search to only
videos that can be embedded into a webpage. If you specify a value for
this parameter, you must also set the type parameter's value to video.
Acceptable values are: any – Return all videos, embeddable or not.
true – Only retrieve embeddable videos.
source: https://developers.google.com/youtube/v3/docs/search/list#videoEmbeddable
For Swift 4.2 of #JAL's answer you just need to do the following and it will work like a charm with vevo videos:
import UIKit
import youtube_ios_player_helper
class MyYoutubePlayerViewController: UIViewController {
#IBOutlet weak var playerView: YTPlayerView!
private var playerVars: [String : Any] = [
"playsinline" : 1,
"showinfo" : 1,
"rel" : 1,
"modestbranding" : 1,
"controls" : 1,
"origin" : "https://www.youtube.com" ]
override func viewDidLoad() {
super.viewDidLoad()
self.playerView.load(withVideoId: "YQHsXMglC9A", playerVars: playerVars)
}
}

Customizing subtitles with AVPlayer

I was able to display a subtitle track with AVPlayer on iOS 6, but I am not able to customize it. It just shows the same style (a small font size, in white).
Here's how I select the subtitle:
AVMediaSelectionGroup *subtitle = [asset mediaSelectionGroupForMediaCharacteristic: AVMediaCharacteristicLegible];
[self.videoPlayer.currentItem selectMediaOption:subtitle.options[0] inMediaSelectionGroup: subtitle];
And how I'm trying to customize the subtitle:
AVTextStyleRule *rule = [[AVTextStyleRule alloc] initWithTextMarkupAttributes:#{
(id)kCMTextMarkupAttribute_ForegroundColorARGB : #[ #1, #1, #0, #0 ],
(id) kCMTextMarkupAttribute_ItalicStyle : #(YES)}];
self.videoPlayer.currentItem.textStyleRules = #[rule];
No matter if I put this snippet before or after selecting the subtitle, the result is the same.
The AVPlayer is created with a local (file) URL (a mp4 file).
Any thoughts on how to do this?
I asked this question on Apple Developer Forums and I got an answer from an Apple employee:
The textStyleRules property only applies to WebVTT content. Your local file is probably carrying subtitles in TX3G format.
You're right that the documentation doesn't mention this limitation, so you should file a bug so we can get our documentation updated.
So, I'll open a radar to ask that they update the docs and I'll post its number here if someone wants to dupe it.
EDIT:
I created rdar://14923673 to ask Apple to update the docs about this current limitation. I also created rdar://14923755 to ask them to provide support to subtitles in TX3G format.
Please dupe them if you're affected by this issue.
I found workaround to modify text foreground color and background correctly.
Just separate styles to multiple AVTextStyleRule.
func initSubtitleStyle() {
let textStyle:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [
kCMTextMarkupAttribute_CharacterBackgroundColorARGB as String: [0.2,0.3,0.0,0.3]
])!
let textStyle1:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [
kCMTextMarkupAttribute_ForegroundColorARGB as String: [0.2,0.8,0.4,0.0]
])!
let textStyle2:AVTextStyleRule = AVTextStyleRule(textMarkupAttributes: [
kCMTextMarkupAttribute_BaseFontSizePercentageRelativeToVideoHeight as String: 20,
kCMTextMarkupAttribute_CharacterEdgeStyle as String: kCMTextMarkupCharacterEdgeStyle_None
])!
player.currentItem?.textStyleRules = [textStyle, textStyle1, textStyle2]
}
please do not ask me why, that solution come from try and error XD

Resources