这可能看起来很荒谬,但是如何在Objective-C中将CMTime的秒数输出到控制台?我只需要将值除以时间刻度,然后以某种方式在控制台中看到它.
所以我有一个视频的CMTime.如何将其转换为一个很好的字符串,如照片应用程序中的视频持续时间标签.是否有一些方便的方法来处理这个问题?谢谢.
AVURLAsset* videoAsset = [AVURLAsset URLAssetWithURL:url options:nil];
CMTime videoDuration = videoAsset.duration;
float videoDurationSeconds = CMTimeGetSeconds(videoDuration);
Run Code Online (Sandbox Code Playgroud) 我正在创建一个播放铃声的应用程序,我想知道每次播放铃声的当前时间(以毫秒为单位).
CMTime cTime = player_.currentTime; float currentTime = cTime.value/cTime.timescale;
这里的currentTime以秒为单位获取值.如何获得精确的currentTime值,但以毫秒为单位?
如何为当前的播放时间添加5秒?
其实这是我的代码:
CMTime currentTime = music.currentTime;
Run Code Online (Sandbox Code Playgroud)
我不能使用CMTimeGetSeconds(),因为我需要CMTime格式.
谢谢您的回答...
编辑:如何为CMTime设置变量?
我正在为视频写一些帧AVAssetWriterInputPixelBufferAdaptor
,而且时间上的行为并不是我所期望的.
如果我只写一帧:
[videoWriter startSessionAtSourceTime:kCMTimeZero];
[adaptor appendPixelBuffer:pxBuffer withPresentationTime:kCMTimeZero];
Run Code Online (Sandbox Code Playgroud)
这给我一个长度为零的视频,这是我所期待的.
但是,如果我继续添加第二帧:
// 3000/600 = 5 sec, right?
CMTime nextFrame = CMTimeMake(3000, 600);
[adaptor appendPixelBuffer:pxBuffer withPresentationTime:nextFrame];
Run Code Online (Sandbox Code Playgroud)
我得到十秒的视频,我期待五个.
这里发生了什么?难道withPresentationTime
莫名其妙定置了框架和持续时间都开始?
请注意,我没有要求endSessionAtSourceTime
,只是finishWriting
.
我尝试捕获视频:https:
//developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW26
var maxDuration : CMTime = CMTimeMake(seconds, preferredTimeScale)
aMovieFileOutput.maxRecordedDuration = CMTimeMake(seconds, preferredTimeScale)
Run Code Online (Sandbox Code Playgroud)
1行有错误:使用模块'CMTime'作为类型
2行有错误:使用未解析的标识符'CMTimeMake'
我做错了什么?
这应该是一个简单的.我有一个AVPlayer
播放视频文件,我希望能够跳到特定的时间,但我在理解CMTime
工作方式时遇到了一些麻烦.
我需要以秒为单位指定时间.例如:如果我想跳到第二个10.8我想做这样的事情:
[self.avPlayer.currentItem seekToTime:CMTimeMakeWithSeconds(10.8, 1];
Run Code Online (Sandbox Code Playgroud)
但我没有得到我想要的结果.
var songs = MPMediaQuery()
var localSongs = songs.items
songList = NSMutableArray(array: localSongs)
tableView.reloadData()
var song = MPMediaItem(coder: songList[0] as NSCoder)
var currentItem = AVPlayerItem(URL: song.valueForProperty(MPMediaItemPropertyAssetURL) as NSURL)
player.replaceCurrentItemWithPlayerItem(currentItem)
player.play()
var songTitle: AnyObject! = song.valueForProperty(MPMediaItemPropertyTitle)
songName.text = songTitle as? String
sliderOutlet.value = Float(player.currentTime()) // <<-Error here
Run Code Online (Sandbox Code Playgroud)
我正在构建一个音乐播放器,我想要一个滑块来显示歌曲的持续时间,但是我收到了这个错误
找不到接受提供的参数的'init'的重载
我认为问题是将CMTime转换为Float.
CMTimeCompare如何工作?Apple似乎已经从他们的文档中遗漏了返回值.
我假设如果时间相等则返回零并返回正或负1,基于哪个更大?
cmtime ×10
ios ×7
avplayer ×3
objective-c ×3
avfoundation ×2
iphone ×2
swift ×2
c ×1
cocoa-touch ×1
console ×1
uislider ×1
xcode ×1