Skip to content

Commit

Permalink
add KSMEPlayer demo fix #573
Browse files Browse the repository at this point in the history
  • Loading branch information
kingslay committed Oct 9, 2023
1 parent 4b41ee4 commit 160c752
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Demo/SwiftUI/Shared/TracyApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ class APPModel: ObservableObject {
activeM3UURL = activeM3UModel.m3uURL
Task { @MainActor in
_ = try? await activeM3UModel.parsePlaylist()
self.activeM3UModel = activeM3UModel
// 为了解决第一次添加m3u。没有数据的问题,所以需要在查询结果出来之后,在设置下。
if activeM3UModel == self.activeM3UModel {
self.activeM3UModel = activeM3UModel
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion Demo/demo-iOS/demo-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -20,6 +20,7 @@
AC3E54AB24B9E810002B6B1B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AC3E498E24B9CB5E002B6B1B /* LaunchScreen.storyboard */; };
AC3E54AC24B9E815002B6B1B /* Localized.strings in Resources */ = {isa = PBXBuildFile; fileRef = AC3E491D24B98CEB002B6B1B /* Localized.strings */; };
AC458DE621DF830F00BD4CF9 /* AudioViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC458DE521DF830F00BD4CF9 /* AudioViewController.swift */; };
AC68AA322AD3FA320061A4CA /* MEPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC68AA312AD3FA310061A4CA /* MEPlayerViewController.swift */; };
AC80332224BA1A2F002B3D40 /* hevc.mkv in Resources */ = {isa = PBXBuildFile; fileRef = AC80331E24BA1A2F002B3D40 /* hevc.mkv */; };
ACA2123E2756169900F58F75 /* raw.h264 in Resources */ = {isa = PBXBuildFile; fileRef = ACA2123D2756169900F58F75 /* raw.h264 */; };
ACE8052D2A83B92800690A9B /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = ACE8052C2A83B92800690A9B /* RootViewController.swift */; };
Expand All @@ -46,6 +47,7 @@
AC3E498C24B9CA67002B6B1B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localized.strings"; sourceTree = "<group>"; };
AC3E498E24B9CB5E002B6B1B /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
AC458DE521DF830F00BD4CF9 /* AudioViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioViewController.swift; sourceTree = "<group>"; };
AC68AA312AD3FA310061A4CA /* MEPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MEPlayerViewController.swift; sourceTree = "<group>"; };
AC7E04DB2414DA5E00B0F540 /* libxml2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxml2.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/lib/libxml2.tbd; sourceTree = DEVELOPER_DIR; };
AC80331E24BA1A2F002B3D40 /* hevc.mkv */ = {isa = PBXFileReference; lastKnownFileType = file; path = hevc.mkv; sourceTree = "<group>"; };
ACA2123D2756169900F58F75 /* raw.h264 */ = {isa = PBXFileReference; lastKnownFileType = file; path = raw.h264; sourceTree = "<group>"; };
Expand Down Expand Up @@ -106,6 +108,7 @@
AC08615A20B69A4500D801FC /* Info.plist */,
AC3E491D24B98CEB002B6B1B /* Localized.strings */,
AC80331A24BA1A2F002B3D40 /* Resources */,
AC68AA312AD3FA310061A4CA /* MEPlayerViewController.swift */,
);
path = "demo-iOS";
sourceTree = "<group>";
Expand Down Expand Up @@ -275,6 +278,7 @@
AC458DE621DF830F00BD4CF9 /* AudioViewController.swift in Sources */,
AC08619620B69AB400D801FC /* DetailViewController.swift in Sources */,
AC08614F20B69A4500D801FC /* AppDelegate.swift in Sources */,
AC68AA322AD3FA320061A4CA /* MEPlayerViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
38 changes: 38 additions & 0 deletions Demo/demo-iOS/demo-iOS/MEPlayerViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// MEPlayerViewController.swift
// demo-iOS
//
// Created by kintan on 2023/10/9.
// Copyright © 2023 kintan. All rights reserved.
//

import Foundation
import KSPlayer
class MEPlayerViewController: UIViewController {
private var player: MediaPlayerProtocol!
override func viewDidLoad() {
super.viewDidLoad()
let definition = testObjects[0].definitions[0]
player = KSMEPlayer(url: definition.url, options: definition.options)
player.delegate = self
player.view?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
player.view?.frame = view.bounds
player.contentMode = .scaleAspectFill
player.prepareToPlay()
view.addSubview(player.view!)
}
}

extension MEPlayerViewController: MediaPlayerDelegate {
func readyToPlay(player: some KSPlayer.MediaPlayerProtocol) {
player.play()
}

func changeLoadState(player _: some KSPlayer.MediaPlayerProtocol) {}

func changeBuffering(player _: some KSPlayer.MediaPlayerProtocol, progress _: Int) {}

func playBack(player _: some KSPlayer.MediaPlayerProtocol, loopCount _: Int) {}

func finish(player _: some KSPlayer.MediaPlayerProtocol, error _: Error?) {}
}

0 comments on commit 160c752

Please sign in to comment.