avplayer

Why this Objective-C code won't play an AVPlayerViewController video?

做~自己de王妃 提交于 2019-12-30 05:18:06
问题 Both are in viewDidLoad(). What's wrong with this objective-c source file? The swift version works like a charm... Xcode ver. 8.2 iOS 10 Swift (OK): let path : String = Bundle.main.path(forResource: "charlie", ofType: "mp4")! let movieurl : URL = URL(fileURLWithPath: path) let movie : AVPlayerViewController = AVPlayerViewController() movie.view.frame = self.view.bounds let player : AVPlayer = AVPlayer(url: movieurl) movie.player = player self.view.addSubview(movie.view) player.play()

When Video plays using AVPLayer, it stops background music ios

不想你离开。 提交于 2019-12-30 03:14:07
问题 I am playing video using AVPlayer , it stops iPhone's music which is on going in background. Please help me to resolve let item1 = AVPlayerItem.init(URL: NSURL(string:path)) player = AVPlayer(playerItem: item1) layer?.player = player; player?.play() 回答1: My movies are for animations; they have no sound. To let other sound continue playing, in Swift: // None of our movies should interrupt system music playback. _ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category

Playing video with AVPlayer and recording sound with AVAudioRecorder simultaneously

扶醉桌前 提交于 2019-12-30 00:39:37
问题 I was googling this problem for many days but I didn't find a solution for my simple problem. I'm trying to play a video while recording sound. Recording sound works fine without the video. And the video works fine without the recording. As soon as I put both together, the recording throws values which do not react on sound and the video is not playing anymore. By the way this happens only on my device (iPhone 4 / iOS5). In the simulator everything works fine. This is a reduced version of my

iPhone ios4 - Replacing iPod dock icon whilst playing background audio stream

给你一囗甜甜゛ 提交于 2019-12-29 14:56:55
问题 I've figured out how I can get audio playing in the background on ios4, however I've noticed that some apps also replace the iPod dock icon with their own app icon. (Last.fm & Spotify for example). They are also able to use the dock media controls to pause and resume their streams. Does anyone know how to do this? Thanks 回答1: It's easy you have to respond to the Remote Control Events. This also lets you control your app with the headset. In lets say viewDidLoad call: [[UIApplication

How to play multiple Audio Files simultaneously using AVPlayer?

▼魔方 西西 提交于 2019-12-29 09:35:23
问题 I am trying to play multiple audio files using 2 AVPlayer instances, but one of the player stops for a fraction of a second rather than playing all audio files simultaneously. The logic of the program is as follows: var player: AVPlayer? will stream an audio file from my database. On its own is playing perfectly. fileprivate var countPlayer: AVPlayer? plays the count number of the current item being played by var player . The count is a sequence of 1 to 8 and for each digit I am storing

How to stop a video in AVPlayer?

纵然是瞬间 提交于 2019-12-29 04:34:07
问题 I am using this code to play video file using avplayer how do I stop it [videoView setHidden:NO]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path2 = [documentsDirectory stringByAppendingPathComponent:saveFileName]; NSURL *url1 = [[NSURL alloc] initFileURLWithPath: path2]; videoPlayer = [AVPlayer playerWithURL:url1] ; self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer

Subtitles for AVPlayer/MPMoviePlayerController

三世轮回 提交于 2019-12-29 02:52:47
问题 I am using m3u8 video format for streaming the video and now I need to display subtitles for the same. I searched in Apple Documentation and found that I can achieve this by using the closedCaptionDisplayEnabled property of AVPlayer . I am interested to know what should be the format of subtitles? Will the .srt format do? Also can I achieve the same using MPMoviePlayerController ? Any help is appreciated. 回答1: Update 10/30/2018: It's worth checking this answer by an Apple engineer (Thanks to

AVPlayer之音乐播放

倖福魔咒の 提交于 2019-12-28 23:25:44
今天来整理一下以前自己学到的AVPlayer播放音乐的功能,这虽然简单,但是温故而知新嘛!下面说说做一个简单播放界面的思路和核心代码. 1.创建单例类MusicManager,模型类Music,音乐控制器MusicViewController, 和一个MusictableViewController 2.在单例中声明单例和获取数据,初始化模型数组 3.在表示图控制器中引入单例拿到数据:[[MusicManager shareInstance] getData];//这是单例中获取数据的方法 4.在表视图中显示数据 5.从表视图跳转到MusicViewController的方式:首先需要在故事版中将控制器和MusicViewController相关联,再设置storyboadID: 1):在点击cell的方法中 通过表视图的故事版实例化MusicViewController 然后模态或者push过去 MusicViewController *musicVC = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboadID"]; 2:通过从表视图的cell连线到MusicViewController上, 然后在表视图的下面方法中跳转:需要设置segue的标示符 - (void)prepareForSegue

Seek to a certain position in AVPlayer right after the asset was loaded

冷暖自知 提交于 2019-12-28 11:47:07
问题 This works: I have an AVPlayer which plays a video right after it was loaded. And this works fine. This doesn't : Instead of starting the video at the beginning, I want to play it at a given position. So I wait until the asset is ready for Play using KVO: BOOL isReadyToSeek = (self.playerItem.status == AVPlayerStatusReadyToPlay) And then seek to the given time [playerItem seekToTime:timeInTheMiddleOfTheVideo completionHandler:myHandler]; But the player will always start at the beginning of

AVFoundation (AVPlayer) supported formats? No .vob or .mpg containers?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-28 06:00:27
问题 Using AVPlayer in a Mac app here to play random videos in fullscreen from a folder, but when I try to play .vob files or .mpg files I just get a black screen that lasts as long as the video lasts. Does AVFoundation not support playback from these containers? I figured that since they were playable with stock QuickTime Player they would also work with AVPlayer. 回答1: The AVURLAsset class has a static methods that you can query for supported video UTIs: + (NSArray *)audiovisualTypes On 10.9.1 it