TvOS video player changes:

Media info view changes
Fix crash when trying to set now playing artwork
This commit is contained in:
Stephen Byatt 2021-06-22 18:36:38 +10:00
parent 2229f1ca58
commit 8f97d4e2e8
3 changed files with 71 additions and 60 deletions

View File

@ -38,63 +38,74 @@ struct MediaInfoView: View {
var body: some View {
if let item = item {
HStack {
HStack(spacing: 30) {
VStack {
ImageView(src: item.type == "Episode" ? item.getSeriesPrimaryImage(maxWidth: 200) : item.getPrimaryImage(maxWidth: 200), bh: item.type == "Episode" ? item.getSeriesPrimaryImageBlurHash() : item.getPrimaryImageBlurHash()) .frame(width: 200, height: 300)
.cornerRadius(10)
Spacer()
}
.padding(.leading, 200)
VStack(alignment: .leading, spacing: 10) {
if item.type == "Episode" {
Text(item.seriesName ?? "Series")
.fontWeight(.bold)
Text(item.name ?? "Episode")
.foregroundColor(.secondary)
}
else
{
Text(item.name ?? "Movie")
.fontWeight(.bold)
}
VStack(alignment: .leading) {
HStack(spacing: 10) {
if item.type == "Episode" {
Text(item.seriesName!)
.font(.title3)
Text("S\(item.parentIndexNumber ?? 0):E\(item.indexNumber ?? 0)\(item.name!)")
.font(.headline)
.foregroundColor(.secondary)
}
else
{
Text(item.name!)
.font(.title3)
Text("S\(item.parentIndexNumber ?? 0) • E\(item.indexNumber ?? 0)")
if let date = item.premiereDate! {
Text("")
Text(formatDate(date: date))
}
} else if let year = item.productionYear {
Text(String(year))
}
HStack(spacing: 10) {
Text(String(item.productionYear!))
if item.runTimeTicks != nil {
Text("")
Text(item.getItemRuntime())
}
if let rating = item.officialRating {
Text("")
Text(formatRunningtime())
Text("\(rating)").font(.subheadline)
.fontWeight(.semibold)
.padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4))
.overlay(RoundedRectangle(cornerRadius: 2)
.stroke(Color.secondary, lineWidth: 1))
if item.officialRating != nil {
Text("")
Text("\(item.officialRating!)").font(.subheadline)
.fontWeight(.semibold)
.padding(EdgeInsets(top: 1, leading: 4, bottom: 1, trailing: 4))
.overlay(RoundedRectangle(cornerRadius: 2)
.stroke(Color.secondary, lineWidth: 1))
}
}
.padding(.top)
.foregroundColor(.secondary)
Text(item.overview!)
.padding([.top, .trailing])
.foregroundColor(.secondary)
Spacer()
}
.foregroundColor(.secondary)
if let overview = item.overview {
Text(overview)
.padding(.top)
.foregroundColor(.secondary)
}
Spacer()
}
Spacer()
}
.frame(maxWidth: .infinity)
.padding(.leading, 350)
.padding(.trailing, 200)
}
else {
EmptyView()
@ -102,16 +113,11 @@ struct MediaInfoView: View {
}
func formatRunningtime() -> String {
let timeHMSFormatter: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .brief
formatter.allowedUnits = [.hour, .minute]
return formatter
}()
func formatDate(date : Date) -> String{
let formatter = DateFormatter()
formatter.dateFormat = "d MMM yyyy"
let text = timeHMSFormatter.string(from: Double(item!.runTimeTicks! / 10_000_000)) ?? ""
return text
return formatter.string(from: date)
}
}

View File

@ -80,17 +80,17 @@
</subviews>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<containerView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lie-K8-LNT">
<rect key="frame" x="88" y="57" width="1744" height="635"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" red="0.10195661340000001" green="0.1019650772" blue="0.1060298011" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<segue destination="odZ-Ww-zvF" kind="embed" identifier="infoView" id="i7y-hI-hVh"/>
</connections>
</containerView>
</subviews>
<viewLayoutGuide key="safeArea" id="IS7-IU-teh"/>
</view>
<containerView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lie-K8-LNT">
<rect key="frame" x="152" y="68" width="1615" height="635"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" red="0.10195661340000001" green="0.1019650772" blue="0.1060298011" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<connections>
<segue destination="odZ-Ww-zvF" kind="embed" identifier="infoView" id="i7y-hI-hVh"/>
</connections>
</containerView>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" animating="YES" style="large" translatesAutoresizingMaskIntoConstraints="NO" id="WHW-kl-wkr">
<rect key="frame" x="928" y="508" width="64" height="64"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>

View File

@ -349,8 +349,13 @@ class VideoPlayerViewController: UIViewController, VideoPlayerSettingsDelegate,
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = playbackTicks
if let imageData = NSData(contentsOf: manifest.getPrimaryImage(maxWidth: 200)) {
let artworkImage = UIImage(data: imageData as Data)
nowPlayingInfo[MPMediaItemPropertyArtwork] = artworkImage
if let artworkImage = UIImage(data: imageData as Data) {
let artwork = MPMediaItemArtwork.init(boundsSize: artworkImage.size, requestHandler: { (size) -> UIImage in
return artworkImage
})
nowPlayingInfo[MPMediaItemPropertyArtwork] = artwork
print("set artwork")
}
}
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo