Adding subtitles in react native video - react-native

I went through the react-native props and come to know they added selectedTextTrack for subtitle support. But, how exactly it can be added I'm unable to write code.
Can I add a file(.SRT) as input for a subtitle?
<Video
source={{uri: ''}}
resizeMode={this.state.resizeMode}
style={mediaPlayerStyle.player}
rate={this.state.rate}
volume={this.state.volume}
paused={this.state.paused}
onLoad={this.onLoad}
onProgress={this.onProgress}
onEnd={this.onEnd}
repeat={true}
selectedTextTrack={{
type: 'index',
value: 0
}}
textTracks={[
{
index: 0,
title: "English CC",
language: "en",
type: TextTrackType.VTT, // "text/vtt"
uri: "https://bitdash-a.akamaihd.net/content/sintel/subtitles/subtitles_en.vtt"
},
{
index: 1,
title: "Spanish Subtitles",
language: "es",
type: TextTrackType.SRT, // "application/x-subrip"
uri: "https://durian.blender.org/wp-content/content/subtitles/sintel_es.srt"
}
]}
/>
So basically i want to add subtitles for one video in various languages, If it is .srt file that would be a great help

use react-native-video-controls that renders subtitles on top of the video using JavaScript, which you might try.
In order to use subtitles you should follow the below instructions : First if your subtitle format is srt you should convert it to JSON(use websites like : http://multiverso.me/srtToJSON/) Then when you got the array of JSONs, you can pass this array to VideoPlayer as below :
<VideoPlayer subtitle={this.props.subtitle}/>
The subtitle prop expects the JSON to have the following key-value format:
[{
"startTime": "00:00:04,123", //hh:mm:ss,SSS
"endTime": "00:00:05,001",
"text": "When you convert your subtitle file, you might need to modify your JSON"
},
{
"startTime": "00:00:08,008",
"endTime": "00:00:09,876",
"text": "Before passing it to the VidePlayer component"
}]

Related

Quill is not working with vuejs and showing arrow image

I've followed the quill playground guide but using vuejs and it doesn't work. There's no error on the browser but a weird arrow is showing.
Example: https://codepen.io/danny1014/pen/gOLZNZQ
var quill = new Quill("#quill-container", {
modules: {
toolbar: [
[{ header: [1, 2, false] }],
["bold", "italic", "underline"],
["image", "code-block"]
]
},
scrollingContainer: "#scrolling-container",
placeholder: "Compose an epic...",
theme: "bubble"
});
Did you import css file of theme "bubble"?
Something like #import "~quill/dist/quill.snow.css";
Try using snow theme instead of bubble

Not able to render image in React Native

I'm trying to load a JPG image from my local folder in my react-native application.
The image is stored inside assets folder which I''m trying to render inside Image tag
Here's my JSON object
{
title: 'Device 2',
image: '../assets/imgs/device_default.jpg',
cta: 'View device',
mac: '1234-xxxx-xxxx-5678'
},
Here's my code for the same
<Block flex style={imgContainer}>
<Image source={{uri: item.image}} style={imageStyles} />
</Block>
here item contains the props value. I can iterate other values like title and mac
but not able to render the image.
Can anyone help me on this??
JSON
title: 'Device 2',
src : require('../assets/imgs/device_default.jpg'),
cta: 'View device',
mac: '1234-xxxx-xxxx-5678'
},
HTML
<Block flex style={imgContainer}>
<Image source={item.src} style={imageStyles} />
</Block>
Got the exact solution here
dynamic paths in require are not currently supported.The only allowed way to refer to an image in the bundle is to literally write require('name-of-the-asset') in the source.
you need to add require for image in your json.Check below example
const Profiles=[
{
"id" : "1",
"name" : "Peter Parker",
"src" : require('../images/user1.png'),
"age":"70",
},
{
"id" : "2",
"name" : "Barack Obama",
"src" : require('../images/user2.png'),
"age":"19",
},
{
"id" : "3",
"name" : "Hilary Clinton",
"src" : require('../images/user3.png'),
"age":"50",
}
]
export default Profiles;

How to Delete html tags form responseJson in react native?

How can I delete html tags? I need to show description, but html tag not support in react native.
json:
[
{
"id": 73,
"name": "Hello World",
"status": "publish",
"description": "<p>hello</p>\n",
...
codes:
componentDidMount(){
return fetch('example.com/testttttttttttttttttttttttttttttttttt')
.then((response)=>response.json()).
then((responseJson)=>{
let ds = new ListView.DataSource({rowHasChanged:(r1,r2)=>r1!=r2});
this.setState({
isLoading:false,
dataSource:ds.cloneWithRows(responseJson)
});
}).catch((error)=>console.error(error));
}
and listView:
<ListView
dataSource={this.state.dataSource}
renderRow={ (rowData)=>
<View style={{width:'100%',height:40}}>
<View style={{marginTop:5,marginBottom:5}}>
<Text>{rowData.name}</Text>
<Text>{rowData.description}</Text>
</View>
</View>
}
/>
Stripping html tags is not a trivial problem. Many issues have been discussed in the question Strip HTML from Text JavaScript.
In my opinion, the best approach would be to use a library like striptags. Then your code would look like:
<Text>{striptags(rowData.description)}</Text>
Another, more naive implementation could use String.prototype.replace:
<Text>{rowData.description.replace(/<(?:.|\n)*?>/gm, '')}</Text>

Export DataTables to PDF is repeating the header

I am using the function to export PDF from jquery DataTables. It works but it repeats the header like the image below:
Does anyone know of any way to export not repeating the header?
$("#table").DataTable({
buttons: [
{
text: '<i class="fas fa-file-pdf"></i> PDF',
extend: 'pdf',
className: 'btn btn-danger',
orientation: 'landscape',
title: 'My table to PDF',
pageSize: 'A3',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
}
}
],
responsive : true,
paging : true,
searching : true
});
It is not so well documented, but after googling around in the pdfmake universe I realized there is a headerRows attribute that defines how many pages the header should be repeated on. This can be manipulated through DataTables' customize(doc) callback :
buttons: [{
extend: 'pdfHtml5',
customize: function(doc) {
doc.content[1].table.headerRows = 0
}
}]
This will prevent the headers from being repeated, i.e only be included on the first page "0".
Demo -> https://jsfiddle.net/mzaudL7c/
Note: The structure of doc.content can vary depending on your setup. So if it not work for you 1:1, investigate doc to find the correct index.

refs working on iOS but undefined on Android - React Native

So I have two components
<TouchableInput
onPress={() => this.interestedInPicker.togglePicker()}
/>
<RNPickerSelect
placeholder={{}}
items={[
{
label: 'text',
value: 'value`,
},
{
label: 'text'
value: 'value',
},
{
label: 'text',
value: 'value',
},
]}
onValueChange={restInput.onChange}
style={styles.interestedInPicker}
value={restInput.value}
ref={ref => (this.interestedInPicker = ref)}
/>
RNPickerSelect has height of 0 so it is hidden.
When I press on the TouchableInput I want the function togglePicker to trigger. This works on iOS but logs undefined on Android. When I console.log this.interestedInPicker I can see the method I need but when I log the whole expression it is undefined. Any idea what is going on ?
I opened this as an issue for library RNPickerSelect about a month ago.
It is a known problem. The issue is that they need a way to trigger the picker programatically. You might be able to find a temporary solution HERE