Skip to content
Video Player preview
Rendered from the SwiftUI source on this page.

Video Player

From syxUI — written for both platforms, not translated between them.

A self-contained video player component — SwiftUI, gradient placeholders, no image assets needed.

Cards · SwiftUI · iOS 17

  • cards
  • swiftui

The actual source

VideoPlayerCard.swift
// Video Player · syxUI · https://syxui.dev/components/media-video
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

func mediaGradient(_ i: Int) -> LinearGradient {
    let pairs: [(Color, Color)] = [
        (Color(red: 0.98, green: 0.42, blue: 0.36), Color(red: 0.85, green: 0.18, blue: 0.22)),
        (Color(red: 0.36, green: 0.42, blue: 0.9), Color(red: 0.16, green: 0.18, blue: 0.42)),
        (Color(red: 0.2, green: 0.6, blue: 0.45), Color(red: 0.08, green: 0.3, blue: 0.24)),
        (Color(red: 0.55, green: 0.4, blue: 0.85), Color(red: 0.3, green: 0.16, blue: 0.5)),
    ]
    let p = pairs[i % pairs.count]
    return LinearGradient(colors: [p.0, p.1], startPoint: .topLeading, endPoint: .bottomTrailing)
}

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Video player card
struct VideoPlayerCard: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            RoundedRectangle(cornerRadius: 14, style: .continuous).fill(mediaGradient(1))
                .aspectRatio(16.0/9.0, contentMode: .fit)
                .overlay {
                    Image(systemName: "play.fill").font(.system(size: 22)).foregroundStyle(.white)
                        .frame(width: 54, height: 54).background(.ultraThinMaterial, in: Circle())
                }
                .overlay(alignment: .bottomTrailing) {
                    Text("2:14").font(.system(size: 11, weight: .semibold)).foregroundStyle(.white)
                        .padding(.horizontal, 7).padding(.vertical, 3).background(.black.opacity(0.5), in: Capsule())
                        .padding(10)
                }
            GeometryReader { g in
                ZStack(alignment: .leading) {
                    Capsule().fill(Color.primary.opacity(0.12)).frame(height: 4)
                    Capsule().fill(Color.primary).frame(width: g.size.width * 0.4, height: 4)
                    Circle().fill(Color.primary).frame(width: 11, height: 11).offset(x: g.size.width * 0.4 - 5)
                }
            }.frame(height: 11)
        }.formaCard(12)
    }
}
iOS 17 · 1 dependencies

Dependencies

SwiftUI
  • mediaGradient

Requires iOS 17