如何使用xmpp清除视频和音频?

时间:2017-05-27 09:15:46

标签: ios objective-c xmpp xmppframework

我使用以下代码聊天app.i共享视频和音频但是花费了太多时间。所以任何人都有解决方案,请给我。

对于音频: -

NSData *dataAudio = [NSData dataWithContentsOfFile:filepath];

dataAudio=[dataAudio gzippedData];

NSString *audioStr=[dataAudio base64EncodedStringWithOptions:0];

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];

[message addAttributeWithName:@"type" stringValue:@"set"];
[message addAttributeWithName:@"id" stringValue:@"ANY_ID_NAME"];
[message addAttributeWithName:@"from" stringValue:[[self xmppStream] 
 myJID].full];
[message addAttributeWithName:@"to" stringValue:dictionary[@"to"]];
[message addAttributeWithName:@"chattype" stringValue:@"singlechat"];

 NSXMLElement *data=[NSXMLElement elementWithName:@"data"];
[data addAttributeWithName:@"xmlns" 
 stringValue:@"http://jabber.org/protocol/ibb"];
[data addAttributeWithName:@"seq" stringValue:@"0"];
[data addAttributeWithName:@"sid" stringValue:@"Stream0002"];

[data setStringValue:audioStr];

 NSXMLElement *xmlmediatype=[NSXMLElement elementWithName:@"mediatype"];
[xmlmediatype setStringValue:@"audio"];

[message addChild:xmlmediatype];
[message addChild:data];


 [[self xmppStream] sendElement:message];

视频: -

videoData = [NSData dataWithContentsOfURL:videourl];
NSString *videoStr=[videoData base64EncodedStringWithOptions:0];

NSXMLElement *message = [NSXMLElement elementWithName:@"message"];

[message addAttributeWithName:@"type" stringValue:@"set"];
[message addAttributeWithName:@"id" stringValue:@"ANY_ID_NAME"];
[message addAttributeWithName:@"from" stringValue:[[self xmppStream] 
 myJID].full];
[message addAttributeWithName:@"to" stringValue:dictionary[@"to"]];
[message addAttributeWithName:@"chattype" stringValue:@"singlechat"];

NSXMLElement *data=[NSXMLElement elementWithName:@"data"];
[data addAttributeWithName:@"xmlns" 
stringValue:@"http://jabber.org/protocol/ibb"];
[data addAttributeWithName:@"seq" stringValue:@"0"];
[data addAttributeWithName:@"sid" stringValue:@"Stream0002"];

[data setStringValue:videoStr];

NSXMLElement *xmlmediatype=[NSXMLElement 
elementWithName:@"mediatype"];
[xmlmediatype setStringValue:@"video"];

[message addChild:xmlmediatype];
[message addChild:data];


[[self xmppStream] sendElement:message];

使用上面的代码视频和音频shar正在运行,但共享需要花费太多时间。有时它会给出错误时间。

所以任何人都有与此相关的解决方案或代码,请帮助我。

感谢。

0 个答案:

没有答案