YouTube Video Player App
import Felgo 4.0
import QtQuick 2.0
import QtQuick.Layouts 1.3
import QtMultimedia 5.0
import Qt5Compat.GraphicalEffects
Item {
id: feedVideo
width: parent ? parent.width - 2 * spacing : 0
height: topSpacer.height + content.height + bottomSpacer.height
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined
property alias previewImageSource: previewImage.source
property alias title: titleItem.text
property string description: ""
property string richDescription: ""
property string richDescriptionPreview: richDescription.substring(0, 150)
property var videoStatistics: []
property real spacing: dp(Theme.navigationBar.defaultBarItemPadding)
property string videoId: ""
property bool showDetails: false
onDescriptionChanged: updateCrossLinks()
property string otherUrl :""
property string spotifyUrl: ""
property string itunesUrl: ""
property string amazonUrl: ""
property string soundcloudUrl: ""
property string facebookUrl: ""
property string instagramUrl: ""
property string twitterUrl: ""
function updateCrossLinks() {
var regex = /(?:(?:https?):\/\/)?([a-zA-Z/\-=%]+\.)+[\w/\-?=%]{2,}/ig;
if(description) {
var results = description.match(regex)
for(var key in results) {
var link = results[key]
if(!link.startsWith("http://") && !link.startsWith("https://"))
link = "https://" + link
if(results[key].includes("spoti.fi") && !spotifyUrl)
spotifyUrl = link
else if(results[key].includes("apple.co") && !itunesUrl)
itunesUrl = link
else if(results[key].includes("amzn.to") && !amazonUrl)
amazonUrl = link
else if(results[key].includes("soundcloud") && !soundcloudUrl)
soundcloudUrl = link
else if(results[key].includes("facebook") && !facebookUrl)
facebookUrl = link
else if(results[key].includes("instagram") && !instagramUrl)
instagramUrl = link
else if(results[key].includes("twitter") && !twitterUrl)
twitterUrl = link
else if(!otherUrl)
otherUrl = link
}
richDescription = description.replace(regex, function(link) { return "<a href='"+link+"'>"+link+"</a>" })
richDescription = "<p>"+richDescription.replace("\n", "</p>\n<p>")+"</p>"
}
else
richDescription = ""
}
Item {
id: topSpacer
height: spacing / 2
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("clicked feed video")
youTubePlayer.visible = false
youTubePlayer.parent = youtubeVideoContainer
youTubePlayer.loadVideo(videoId, true)
youTubePlayer.visible = true
}
}
Item {
id: content
width: parent.width
height: previewImageContainer.height + textPanel.anchors.topMargin + textPanel.height
anchors.top: topSpacer.bottom
layer.enabled: true
layer.effect: DropShadow {
radius: dp(8)
horizontalOffset: dp(2)
verticalOffset: horizontalOffset
color: "#16161400"
}
Item {
id: previewImageContainer
anchors.fill: youtubeVideoContainer
clip: true
AppImage {
id: previewImage
source: Qt.resolvedUrl("../../assets/felgo-logo.png")
width: parent.width
height: parent.height
anchors.centerIn: parent
fillMode: AppImage.PreserveAspectCrop
}
}
Item {
id: youtubeVideoContainer
width: parent.width
height: width / 16 * 9
}
Rectangle {
id: textPanel
width: parent.width
height: detailsCol.height + 2 * detailsCol.spacing
color: "white"
anchors.top: previewImageContainer.bottom
Column {
id: detailsCol
width: parent.width - 4 * spacing
anchors.centerIn: parent
spacing: feedVideo.spacing / 2
Item { width: parent.width; height: px(1) }
AppText {
id: titleItem
color: Theme.secondaryTextColor
width: parent.width
wrapMode: AppText.WrapAtWordBoundaryOrAnywhere
font.pixelSize: sp(14)
}
Item { width: parent.width; height: px(1); visible: socialLinks.visible }
GridLayout {
id: socialLinks
anchors.horizontalCenter: parent.horizontalCenter
visible: height > 0
property real spacing: feedVideo.spacing
columnSpacing: spacing
rowSpacing: spacing
columns: parent.width / (dp(36) + spacing)
property int maxWidth: parent.width - 2 * spacing
property int itemWidth: children.length * children[0].width + children.legnth - 1 * spacing
SocialLink {
targetUrl: otherUrl
source: "../../assets/web.png"
}
SocialLink {
targetUrl: spotifyUrl
source: "../../assets/spotify.png"
}
SocialLink {
targetUrl: itunesUrl
source: "../../assets/itunes.png"
}
SocialLink {
targetUrl: amazonUrl
source: "../../assets/amazon.png"
}
SocialLink {
targetUrl: soundcloudUrl
source: "../../assets/soundcloud.png"
}
SocialLink {
targetUrl: instagramUrl
source: "../../assets/instagram.png"
}
SocialLink {
targetUrl: facebookUrl
source: "../../assets/facebook.png"
}
SocialLink {
targetUrl: twitterUrl
source: "../../assets/twitter.png"
}
}
Item { width: parent.width; height: px(1); visible: socialLinks.visible }
Item {
width: parent.width
height: !showDetails ? descPreviewItem.height : descItem.height
Behavior on height {
PropertyAnimation { duration: 150 }
}
AppText {
id: descPreviewItem
text: richDescriptionPreview + "..."
width: parent.width
wrapMode: AppText.WrapAtWordBoundaryOrAnywhere
color: Theme.secondaryTextColor
font.pixelSize: sp(12)
textFormat: AppText.RichText
visible: !showDetails && showMoreButton.visible
onLinkActivated: nativeUtils.openUrl(link)
}
AppText {
id: descItem
text: richDescription
width: parent.width
wrapMode: AppText.WrapAtWordBoundaryOrAnywhere
color: Theme.secondaryTextColor
font.pixelSize: sp(12)
textFormat: AppText.RichText
visible: !descPreviewItem.visible
onLinkActivated: nativeUtils.openUrl(link)
}
}
AppButton {
id: showMoreButton
text: !showDetails ? "show more" : "show less"
flat: true
textSize: dp(10)
minimumHeight: dp(24)
anchors.horizontalCenter: parent.horizontalCenter
onClicked: showDetails = !showDetails
visible: richDescriptionPreview !== richDescription
textColor: "#FF0000"
}
FeedVideoStatistics { statistics: videoStatistics }
}
}
}
Item {
id: bottomSpacer
anchors.bottom: parent.bottom