This is a basic iOS application that demonstrates how to play a video file using AVKit and AVFoundation. It includes a single "Play Video" button that, when tapped, presents a video player with standard controls.
- Plays a video file from the app's bundle.
- Uses
AVPlayerViewController
for video playback with built-in controls. - Simple and easy-to-understand code.
- Xcode 15 or later
- iOS 17 or later (or adjust the code for compatibility with older versions)
- Clone this repository.
- Open the
SimpleVideoPlayer.xcodeproj
file in Xcode. - Make sure the video file ("Cauchy-Schwarz inequality.mp4") is included in your project and that the file name in the code (
findVideo()
function) matches the actual file name. - Build and run the app on a simulator or device.
- Tap the "Play Video" button.
- The video player will appear and start playing the video.
- Use the standard controls on the player to play, pause, adjust volume, etc.
The main logic for video playback is in ViewController.swift
.
viewDidLoad()
: Sets up the "Play Video" button and its constraints.playButtonTapped()
: Called when the button is tapped; triggers thefindVideo()
function.findVideo()
: Locates the video file, creates anAVPlayer
, and presents anAVPlayerViewController
to play the video.
Feel free to fork this repository and submit pull requests for any improvements or bug fixes.